Grails重定向至 GSP 而不是操作
我在控制器“X”上创建了一个名为“updateWithHistory”的新操作,类似于更新。当我从脚手架的 edit.gsp 页面使用此代码时:
我收到 404 错误:
请求的资源 (/GPECAN/WEB-INF/ grails-app/views/X/updateWithHistory.jsp) 不可用。
我不知道为什么 Grails 正在查找视图而不是操作。我不需要该操作的视图,因为它重定向到现有操作(列表、编辑等)。
对于“更新”等默认的脚手架操作,不会发生这种情况。有什么想法吗?
(当然,如果我创建一个名为“updateWithHistory.gsp”的视图,则会显示该视图,但该操作永远不会执行......我很绝望)
I have created a new action called "updateWithHistory" on a controller "X" similar to update. When I use this code from a scaffolded edit.gsp page:
<span class="button"><g:actionSubmit class="save" action="updateWithHistory" value="${message(code: 'default.button.updateWithHistory.label', default: 'Persist')}" /></span>
I get a 404 error:
The requested resource (/GPECAN/WEB-INF/grails-app/views/X/updateWithHistory.jsp) is not available.
I don't know why Grails is looking for the view and not for the action. I don't need a view for that action because it redirects to existing actions (list, edit, etc.).
This does not happen with the default scaffolded actions like "update". Any ideas?
(Of course, if I create a view called "updateWithHistory.gsp", the view is shown, but the action is never executed...I'm desperate)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有两种方法可以解决您的问题,具体取决于您想要实现的目标。
您必须了解的第一件事是引用文档:
因此有两种解决方案:
PS如果您想查看任何“可渲染”结果通过浏览器,您必须使用控制器的动态 render 方法:)
There are two ways to solve your problem, depending what you want to achieve.
First thing that you have to know is quote from documentation:
So two solutions:
P.S. If you want to see any 'renderable' result by browser you have to use controller's dynamic render method :)
您的控制器可能有错误。执行操作后,您需要渲染某些内容或重定向。仔细看看支架控制器代码。
尝试在 updateWithHistory 操作末尾添加以下内容。
You have probably bug in your controller. After your action you need to render something or redirect. Take a good look on scaffolded controller code.
Try to add following on the end of your updateWithHistory action.
好吧,我只是个傻子。这是我的控制器中未捕获的错误;发生了错误情况,但没有特定的视图来处理它,因此控制器尝试重定向到不存在的默认视图。
非常抱歉我的愚蠢并感谢您的帮助
OK, I'm just stupid. It was an uncatched error in my controller; the error situation was ocurring but there was not specific view to handle it, so the controller tried to redirect to an unexisting default view.
Sorry a lot for my stupidity and thanks for your help