views:

77

answers:

1

Hello community!

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!

A: 

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

Paras
I figured it out, thanks for your comment! It turns out that when rendered content includes an attribute such as: <someTag someAttr="" /> where the attribute is blank, the browser requests that information again. Since the object only existed in the context of the first call, the second call bombed. In other words, it had to do with trying to render some XML to a page that was being rendered.
Quad64Bit