Grails 操作被调用两次。帮助!
我正在编写一个 grails 应用程序并遇到一个奇怪的问题。单击页面上的提交按钮时,关联的操作会快速连续调用两次。这会导致一切都严重破坏。以前有其他人见过这个问题吗?下面是我的代码:
来自 GSP 页面:
<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!" />
从控制器:
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;
}
输出:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1994 年 9 月 17 日星期六 00:00:00 美国东部时间
时间1284757543744
**************************
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
空
时间1284757544091
**************************
2010-09-17 17:05:44,100 [http-8080-2] ERROR 错误。GrailsExceptionResolver - null
java.lang.NullPointerException
您可以看到该操作在第一次调用后几毫秒被调用了两次。系统失败,因为在第二次调用时,日期对象为空。有什么想法吗?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你已经解决这个问题了吗?您是否尝试过将操作从显示更改为保存?
而不是
保存方法的名称。在 post 方法上看到“显示”操作非常奇怪。也许 grails 正在幕后做一些事情,因为 grails 做了很多基于约定的事情,你可能甚至没有意识到!
Have you solved this already? Have you tried changing the action from show to save?
instead of
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!!