2014-10-04 83 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> 

任何建议我可以做的最大调用堆栈?

相关问题