Grails操作被调用两次。帮帮我! [英] Grails actions getting called twice. Help!

查看:99
本文介绍了Grails操作被调用两次。帮帮我!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Grails应用程序并遇到一个奇怪的问题。当点击页面上的提交按钮时,相关联的操作会快速连续调用两次。这会导致所有事情都崩溃。有没有其他人看过这个问题?以下是我的代码:



从GSP页面:

 < ; g:form method =postaction =show> 
< h2>自...以来的所有项目< / h2>
< h2>格式< / h2>
< g:radio name =feedTypevalue =RSS2/>< span> RSS 2.0< / span>
< g:radio name =feedTypevalue =ATOM/>< span> Atom< / span>< br />
< hr />
< h2>主题< / h2>
< / g:if>
< g:else>
< / g:其他>
< / g:每个>
< hr />



从控制器: p>

  def show = {
def nodeID = params.nodeID
def feedType
if(params。 feedType.equals(RSS1)){
feedType = FeedType.RSS1;
} else if(params.feedType.equals(RSS2)){
feedType = FeedType.RSS2;
} else {
feedType = FeedType.ATOM;
}
def date = params.startDate
println(!!!!!!!!!!!!!!!!!!!!!!!!!!!!! )
println(date)
println(Time+ System.currentTimeMillis());
println(****************************)
def feed = XMPPListenerService.getFeed(date, feedType,nodeID)
response.contentType =text / xml
response.outputStream<<饲料;





输出:

< blockquote>
!!!!!!!!!!!!!!!!!!!!!!!!!

Sat Sep 17 00:00:00美国东部时间1994年
时间1284757543744

************************ />
!!!!!!!!!!!!!!!!!!!!!!!!!!!!

null

时间1284757544091

****************************

2010-09 -17 17:05:44,100 [http-8080-2] ERROR errors.GrailsExceptionResolver - null

java.lang.NullPointerException -

您可以看到该操作在第一次调用后的几毫秒内被调用两次。系统失败,因为在第二次调用时,日期对象为空。有任何想法吗?谢谢!

解决方案

您是否已经解决了这个问题?您是否曾尝试将节目中的动作改为保存?

 < g:form method =postaction =save > 

而不是

 < g:form method =postaction =show> 

和方法名称保存。在post方法中看到显示动作是很奇怪的。也许grails正在做一些幕后工作,因为grails会根据惯例做很多事情,你甚至可能不知道!!


I'm writing a grails app and running into a strange problem. When clicking the submit button on a page, the associated action gets called twice in rapid succession. This causes everything to break horribly. Has anyone else seen this issue before? Below is my code:

From the GSP page:

<g:form method="post" action="show">
<h2>All items since...</h2>
<g:datePicker name="startDate" precision="day" value="${new Date()}"  /><br/>
<h2>Format</h2>
<g:radio name="feedType" value="RSS1" checked="true"/><span>RSS 1.0</span>
<g:radio name="feedType" value="RSS2"/><span>RSS 2.0</span>
<g:radio name="feedType" value="ATOM"/><span>Atom</span><br/>
<hr />
<h2>Topics</h2>
<g:each in="${list}" var="subscription" status="i">
  <g:if test="${i == 0}">
    <g:radio name="nodeID" value="subscription.name" checked="true"/><span>${subscription.getPrettyName()}</span><br/>
  </g:if>
  <g:else>
    <g:radio name="nodeID" value="${subscription.name}"/><span>${subscription.getPrettyName()}</span><br/>
  </g:else>
</g:each>
<hr/>
<g:submitButton name="getFeedButton" value="Get Feed!" />

From the controller:

def show = {
    def nodeID = params.nodeID
    def feedType
    if(params.feedType.equals("RSS1")){
        feedType = FeedType.RSS1;
    } else if(params.feedType.equals("RSS2")){
        feedType = FeedType.RSS2;
    } else{
        feedType = FeedType.ATOM;
    }
    def date = params.startDate
    println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
    println(date)
    println("Time "+System.currentTimeMillis());
    println("****************************")
    def feed = XMPPListenerService.getFeed(date, feedType, nodeID)
    response.contentType = "text/xml"
    response.outputStream << feed;
}

The output:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Sat Sep 17 00:00:00 EDT 1994
Time 1284757543744
****************************
!!!!!!!!!!!!!!!!!!!!!!!!!!!!
null
Time 1284757544091
****************************
2010-09-17 17:05:44,100 [http-8080-2] ERROR errors.GrailsExceptionResolver - null
java.lang.NullPointerException

You can see the action is being called twice a few milliseconds after the first call. The system fails because at the time of the second call, the date object is null. Any ideas? Thanks!

解决方案

Have you solved this already? Have you tried changing the action from show to save?

<g:form method="post" action="save">

instead of

<g:form method="post" action="show">

and name of the method as save. It is very strange to see see "Show" action on post method. Maybe grails is doing something behind the scene because grails do so many things based on convention you may not be even aware!!

这篇关于Grails操作被调用两次。帮帮我!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆