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!