2014-10-04 81 views
0

最後更新:它似乎是問題與geomap相關,並且不想更新,現在使用jvectormap重寫它,因爲這更符合我的要求。Grails什麼是重新加載gsp的正確方法

所以

得到其中有兩個箱的應用程序,一個包含了一堆控制器(分辨率,區域和東西)的。它會對第二個盒子進行遠程調用,然後將該數據提取出來並提取一堆東西,設置數據然後發送到谷歌可視化。但是,如果我在類中使用渲染,它可以很好地工作,可以看到它提取了正確的變量,並且它們看起來像是從一開始就做的。

問題是,如果我讓它運行不渲染,那麼GSP頁面不會重新加載,它顯示的是相同的代碼最初加載(實際上,所產生消失圖片)

是有一種方法,我應該告訴gsp頁面重新加載或類似?

下面是像一個魅力的作品(如果控制器使輸出)remotesubmit

<g:formRemote name="mapRepmote" on404="alert('not found!')" update="page-body" 
       url="[controller: 'mapren', action:'show']"> 
    <g:if test="${listreg == 'true'}"> 
     Regulation: <g:select name="regsel" from="${reglist}" value="${regreq}" /> 
    </g:if> 
    <g:else> 
     Regulation: ${regreq} 
    </g:else> 

    Resolution: &nbsp;<g:select name="ressel" from="${reslist}" value="${resreq}" /> 

    Region: <g:select name="mapsel" from="${maplist}" value="${mapreq}" /> 

<div id="bupdate"><Button type="submit">Update</Button></div> 
</g:formRemote> 

編輯:究竟是什麼 所以被玩弄和一遍遍得到相同的結果。 因此,來自mapren控制器的顯示操作似乎被調用。我可以看到對db層和所有的調用。如果我添加三個渲染陳述我可以看到,請求在未來。

def show(String regsel, String mapsel, String ressel) { 
     String mapcode 
     switch (mapsel) { 
      case "World": 
       mapcode="world" 
       break 
      case "Europe": 
       mapcode=150 
       break 
      case "Asia": 
       mapcode=140 
       break 
      case "Africa": 
       mapcode=002 
       break 
      case "Central Ameirca": 
       mapcode=017 
       break 
      case "Pacific": 
       mapcode=035 
       break 
      default: 
       mapcode="world" 
     } 

     def restem = ressel.split('x') 
     String mwidth = restem[0] 
     String mheight = restem[1] 
     render "I was asked to show reg: ${params.regsel} <BR>map: ${params.mapsel}<BR>Resolution ${params.ressel}<BR>" 
     render "will generate map for ${regsel} on code ${mapcode} resolutio" 
     render "I will ${mwidth} and ${mheight}" 
     def query = Regstat.where { 
      (reg==regsel) 
     } 
     def regcolumns = [['string', 'Country'],['number', regsel + 'Status']] 
     def results = query.list(sort:"lupdate") 
     def regdata = [] 
     results.each { 
      regdata << [it.country.countryname,it.status] 
     } 
     def RegColors = ['0xF0F0F0','0x66CCFF','0x0000FF','0xCC66FF','0x9900CC','0x7D7D7D'] 
     [reg_columns: regcolumns, reg_data: regdata,reg_colors: RegColors, regioncode: mapcode, wwidth: mwidth, wheight: mheight] 
    } 
} 

但如果我刪除渲染電話,我本來期望的是,show.gsp它將不會加載? 但沒有這樣的運氣。 已附加show.gsp文件。請注意,它是在索引針對它生成第一個geomap時生成的。

<%@ page import="org.grails.plugins.google.visualization.util.DateUtil" %> 
<html> 
    <head> 
     <script src="http://maps.google.com/maps?file=api&v=2&key=ABCDEFG" type="text/javascript"></script> 
     <script type="text/javascript" src="http://www.google.com/jsapi"></script> 
    </head> 
     <body> 

     <script type="text/javascript"> 
      function selectHandler(e) { 
       alert('A table row was selected'); 
      } 
     </script> 
     <gvisualization:geoMap elementId="page-body" showLegend="${false}" region="${regioncode}" width="${wwidth}" height="${wheight}" colors="${reg_colors}" columns="${reg_columns}" data="${reg_data}" /> 


    </body> 
</html> 
+0

這應該沒有任何行動的工作。什麼版本的Grails? – 2014-10-04 12:44:18

+0

2.4東西,不到一個月大。難道是因爲那個div中的gsp最初使用 vrghost 2014-10-04 14:11:55

+0

加載好,groovy 3.6.1,不確定我從2.4得到了什麼。看起來像代碼類的作品,可以看到正確的調用數據庫來收集信息,但由於某些原因,html代碼沒有更新,我可以看到舊的代碼(我加載到div的初始視圖,相同的控制器和操作),以及如果我在瀏覽器上執行查看源的數據。 – vrghost 2014-10-04 15:56:24

回答

0

OK,部分答案,但有一步一對夫婦回來:)

於是四處移動它,並結束了創建其中有一個控制器(staticmapren)mapren的直線前進靜態版本和模板(_mapdisp)。這些似乎確實工作正常,每當請求進入,頁面現在正確更新文本。

問題是geomap只是第一次顯示。 與此相當多的戰鬥,後來意識到,也許(僅僅是可能)JavaScript控制檯可能有話要說這個... 是它,因爲它原來...

Uncaught RangeError: Maximum call stack size exceeded 

紅鯡魚:好吧,也許,似乎是一個人來或不重新加載。它發生在大約40秒後,所以仍然沒有線索爲什麼地圖只是第一次出現

我的問題是,我可以做些什麼呢,我可能會破壞對象,並得到一個新的每一次。

控制器的簡化版本如下:

類StaticmaprenController {

def index() { 
    render "I am an index" 
} 
def show(String regsel, String mapsel, String ressel) { 
    String mapcode 
    mapcode="world" 


    def restem = ressel.split('x') 
    String mwidth = restem[0] 
    String mheight = restem[1] 
    //render "I was asked to show reg: ${params.regsel} <BR>map: ${params.mapsel}<BR>Resolution ${params.ressel}<BR>" 
    //render "will generate map for ${regsel} on code ${mapcode} resolutio" 
    //render "I will ${mwidth} and ${mheight}" 
    def regcolumns = [['string', 'Country'],['number', regsel + ' Status']] 
    def RegColors = ['0xF0F0F0','0x66CCFF','0x0000FF','0xCC66FF','0x9900CC','0x7D7D7D'] 

    def regdata = [['UK','3'],['United States','2'],['Russia','4']] 
    String content = g.render (template:"mapdisp", model:[reg_columns: regcolumns, reg_data: regdata,reg_colors: RegColors, regioncode: mapcode, wwidth: mwidth, wheight: mheight]) 
    render content 
    [reg_columns: regcolumns, reg_data: regdata,reg_colors: RegColors, regioncode: mapcode, wwidth: mwidth, wheight: mheight] 

} 

}

而且_mapdisp模板

 Going to elementId="page-body" <BR> 
     Testing some stuff showLegend="${false}" <BR> 
     Will do region="${regioncode}" <BR> 
     Lets go width="${wwidth}" and height="${wheight}"<BR> 
     And these are the Beutiful colours colors="${reg_colors}" <BR> 
     Now columns columns="${reg_columns}"<BR> 
     And the data="${reg_data}"<BR> 


     <script type="text/javascript"> 
      function selectHandler(e) { 
       alert('A table row was selected'); 
      } 
     </script> 
       <gvisualization:geoMap elementId="geomap2" showLegend="${false}" region="${regioncode}" width="${wwidth}" height="${wheight}" colors="${reg_colors}" columns="${reg_columns}" data="${reg_data}" /> 
    </body> 
    <div id="geomap2"></div> 
</html> 

並獲得地理分佈圖和谷歌可視化你將需要安裝api,並用raw(Google Visualization API. Graphs are not displaying in gsp pages

我也在頁面的主體中加載了api。 (添加以下行)

<%@ page import="org.grails.plugins.google.visualization.util.DateUtil" %> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta name="layout" content="genmap-desk"/> 
     <script src="http://maps.google.com/maps?file=api&v=2&key=ABCDEFG" type="text/javascript"></script> 
     <script type="text/javascript" src="http://www.google.com/jsapi"></script> 

任何建議我可以做的最大調用堆棧?

相關問題