2012-09-29 34 views
0

嗨,我有一個gsp,它將有jq網格和一些最初將加載的模板。 如果有一些事情出錯了控制器這將是拋出flash.warning像flash.warning僅在頁面刷新後纔會顯示

def err = resp?.status?.message?:resp?.status?.message?:message(code:'common.unknown.error') 
flash.warning = message(code:'common.error.default', args:[err]) 
在GSP

我會抓住它

<div id="errorPanel"> 
     <g:if test="${flash.warning}"> 
       <g:message code = "reporting.label" /> 
       <div class="message">${flash.warning}</div> 
    </g:if> 
    </div> 

每一件事情是好的,如果TE控制器拋出該警告僅在頁面刷新後才顯示。 請幫我

我GSP是

<%@ page language="java" import="com.cisco.rms.constants.TicketType" %> 
<html> 
    <head> 
     <meta name="layout" content="main" /> 
     <g:set var="entityName" value="${message(code: 'incident.label', default: '<incident.label>')}" /> 
     <title><g:message code = "incident.list" /></title> 
    </head> 
    <body> 
    <div id="errorPanel"> 
     <g:if test="${flash.warning}"> 
       <g:message code = "reporting.label" /> 
       <div class="message">${flash.warning}</div> 
     </g:if> 
    </div> 
    <div class="ros-pageContainer"> 
     <div id="incidentListContainer" class="rosPanel"> 
      <div id="incidentListHeaderContainer"> 
       <div class="ui-widget-header"> 
        <span class="ros-title"> <g:message code="incident.label.plural" /> </span> 
        <g:include controller="ticket" action="searchTicketsInclude"/> 
        <!-- 
        <span class="header-quick-action">  
         <select name="quickactions"> 
           <option selected> <g:message code="common.quickActions.header" /> </option> 
           <option value="download"><g:message code="common.quickActions.download" /> </option> 
           <option value="list and details"><g:message code="common.quickActions.listAndDetails" /> </option> 
           <option value="list only"><g:message code="common.quickActions.listOnly" /> </option> 
           <option value="list all"><g:message code="common.quickActions.listAll" /> </option> 
           <option value="print list"><g:message code="common.quickActions.printList" /> </option> 
           <option value="columns"><g:message code="common.quickActions.columns" /> </option> 
         </select>          
        </span> --> 
       </div> 
      </div> 
      <jqgrid:wrapper id="incident" /> 
     </div> 
     <g:render template="details"/> 

     <br/> 
     <g:render template="/site/sitesAffected"/> 

     <br/> 
     <g:render template="/device/listForIncident"/> 
     <br/> 
     <g:render template="/workLog/list"/>  
     <br/> 

     <g:render template="/alarm/listForIncident"/> 

    </div> 
    <g:render template="/layouts/gridTemplate" /> 
    <script type="text/javascript"> 

     function searchByTicketId() 
     { 
      var ticketId = $('#ticketId').val(); 
      var id_type = $("input[@name=id_type]:checked").val();; 

      var ext = false; 
      if(id_type == 'external') 
       ext = true; 

      search(ticketId, ext); 
     } 

     function search(ticketId, ext) 
     { 
      var grid = $('#incidentGrid'); 

      grid.jqGrid("clearGridData", true);     
      grid.jqGrid('setGridParam',{postData:{ticketId:ticketId, extTicketId:ext}});    
      grid.trigger('reloadGrid'); 

      // alert('ticketId: ' + ticketId + ' type: ' + id_type + ' external: ' + ext); 
     } 

     function resetSearch() 
     { 
      $('#ticketId').val(''); 

      var grid = $('#incidentGrid'); 
      grid.jqGrid("clearGridData", true) 
      grid.jqGrid('setGridParam',{postData:{ticketId:null}}); 
      grid.trigger('reloadGrid'); 

     } 

     function onIncidentGridComplete() { 
      var devCount = $('#incidentGrid').getGridParam("reccount"); 
      if (devCount == 1) { 
       var rowId = $('#incidentGrid').getDataIDs()[0]; 
       $('#incidentGrid').setSelection(rowId, true); 
      } 
      $(window).trigger('resize'); 
     } 

     var ticketId; 
     var ticketType = '${com.cisco.rms.constants.TicketType.INCIDENT}'; 

     function quickActions(actionsList) 
     { 
      var sel = actionsList.selectedIndex 

      if(sel == 1) 
      { 
       window.open('../workLog/addWorkLog?ticketId=' + ticketId + '&ticketType=' + ticketType, 'Add Worklog', 'width=600,height=600', false) 
      }    
     } 

     function resizeGrid(){ 
      //$('#incidentGrid').jqGrid('setGridHeight',$(window).outerHeight() - 255 - 25 - $("#incidentDetailsContainer").outerHeight()); 
     } 

     function clearDetails() { 
      clearIncDetails(); 
     } 

     function onSelectRow(rowId) { 
      clearDetails(); 
      $('#quickActions').show(); 

      ticketId = $('#incidentGrid').getCell(rowId, 'id'); 
      populateDetails(rowId); 

      var rowMinus1 = parseInt(rowId) - 1; 
      $("#incidentGrid tr").removeClass("ui-state-highlight-1"); 
      $("#incidentGrid tr:eq(" + rowMinus1 + ")").addClass("ui-state-highlight-1"); 
      resizeGrid(); 

      reloadDeviceGrid(ticketId); 
      reloadWorklogs (ticketId, ticketType); 
      reloadSitesAffectedGrid(ticketId, ticketType); 
      reloadAlarms(ticketId); 
     } 

     function populateDetails(rowId) { 
      var grid = $('#incidentGrid'); 
      var id = grid.getCell(rowId, 'id'); 
      var submitDate = grid.getCell(rowId, 'submitDate'); 
      var summary = grid.getCell(rowId, 'summary'); 
      var status = grid.getCell(rowId, 'status'); 
      var type = grid.getCell(rowId, 'type'); 

      var data = {id:id, submitDate:submitDate, summary:summary, status:status, type:type}; 
      populateIncDetails(data); 
     } 




     $(document).ready(function() { 

      <jqgrid:grid 
       id="incident" 
       url="'${createLink(action: 'listByCompanyJSON', params: [ticketId: params.ticketId])}'" 
       colNames=" 
        '${g.message(code:'common.priority')}', 
        '${g.message(code:'common.id')}', 
        '${g.message(code:'user.details.site')}', 
        '${g.message(code:'common.impact')}', 
        '${g.message(code:'incident.opened')}', 
        '${g.message(code:'common.parameters.duration')}', 
        '${g.message(code:'common.status')}', 
        '${g.message(code:'common.description')}', 
        '${g.message(code:'common.type')}' 
       " 
       colModel=" 
        {name:'priority', editable: false, fixed: true, width:'55px'}, 
        {name:'id', editable: false, fixed: true, width:'100px'}, 
        {name:'siteName', editable: false, fixed: true, classes:'ellipsis', width: '200px'}, 
        {name:'impact', editable: false, fixed: true, width:'125px'}, 
        {name:'submitDate', editable: false, fixed:true, width:'125px'}, 
        {name:'duration', editable: false, fixed:true, width:'95px'}, 
        {name:'status', editable: false, fixed: true, width:'65px'}, 
        {name:'summary', editable: false, classes:'ellipsis' }, 
        {name:'type', editable: false, hidden: true} 
       " 

       gridComplete="onIncidentGridComplete" 
       onSelectRow="onSelectRow" 
       resizable="true" 
       sortname="'id'" 
       sortorder="'desc'" 
       height="265" 
       autowidth="true" 
       shrinkToFit="true" 
       scrollOffset="16" 
       viewrecords="true" 
       showPager="true" 
       rowNum="12" 
       datatype="'json'"> 
       <jqgrid:navigation id="incident" refresh="true" /> 
       <jqgrid:resize id="incident" resizeOffset="0" /> 
      </jqgrid:grid> 

      //Strips garbage from grid 
      $("#incidentListContainer").find("#incidentWrapper").first().removeClass("ui-widget-header"); 

      //Wires window resize so grid will fit properly at all sizes 
      $(window).resize(resizeGrid); 

      $(window).trigger('resize'); 



     } 

     ); 

     </script> 
</body> 
</html> 
+0

這種「錯誤檢查」之前或查看GSP首次完成後? – GalmWing

+0

在加載頁面時加載模板並調用稍後的控制器,如果控制器中的某些內容失敗,則應該處理該錯誤並將其顯示給用戶 – Siva

回答

1

這是因爲flash對象只對下一個請求可用,因此只有後刷新頁面。你可以在這裏閱讀 - >http://grails.org/doc/latest/ref/Controllers/flash.html

你想使用Ajax嗎?我不確定Grails 2.x,但是當我使用Grails 1.3.7時,我們必須創建一個解決方法來強制消息在不使用閃存範圍的情況下發布。

0

如果這是你期待的behabiour:

load page A -> call controller -> see flash.warning on page A 

那麼恐怕你得搞清楚顯示消息的其他方式。另外,在執行ajax調用時,flash對象不起作用。

如果你想用AJAX做它,你可以使用params模板,而不是內部:

<g:if test="${params?.variable}"> ... 
相關問題