Grails actions getting called twice. Help!

爷,独闯天下 提交于 2020-01-23 03:20:08

问题


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!


回答1:


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!!



来源:https://stackoverflow.com/questions/3739088/grails-actions-getting-called-twice-help

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!