[英]Spring Web Flow Model Validation won't work properly
I am currently working on a web application, which uses Spring Web Flow for some forms. 我目前正在开发一个Web应用程序,该应用程序将Spring Web Flow用于某些形式。 I want to use the automatic validation powered by spring, so therefore I have
我想使用spring提供的自动验证功能,因此
So far my web flow view page won't go further when Validator is associated, so I can see that it is going to my validate method. 到目前为止,与Validator关联时,我的Web流视图页面不会继续进行下去,因此我可以看到它正在进入我的validate方法。 The problem is that I can't get my error message to show.
问题是我无法显示错误消息。 When testing ${status.error} inside my bind tag, then it returns false, always.
在我的绑定标记中测试$ {status.error}时,它总是返回false。
My Validate method inside my Model Class. 我的Model类中的Validate方法。
public void validateEnterMovieDetails(ValidationContext context) {
if (context.getUserEvent().equals("next")) {
MessageContext messages = context.getMessageContext();
if (this.title.isEmpty() || this.title == null) {
messages.addMessage(new MessageBuilder().error().source("title").code("validation.movie.title.required").build())
}
}
}
My JSP file 我的JSP文件
<form:form modelAttribute="movie" action="${flowExecutionUrl}">
<spring:bind path="title">
<c:if test="${status.error}">
<form:errors path="title" />
</c:if>
</spring:bind>
</form:form>
My problem is that it seems that my validation is working, since when I apply this validate method, then I can't go to the next view in the flow, though My bind can't seem to find any errors at all. 我的问题是,我的验证似乎正在工作,因为当我应用此validate方法时,尽管我的绑定似乎根本找不到任何错误,但我无法转到流程中的下一个视图。
So I hope anyone please can help me solve this problem, since I have tried search the web for answers, and nothing seemed to help. 因此,我希望任何人都可以帮助我解决此问题,因为我已经尝试在网上搜索答案,但似乎没有任何帮助。 You can see the full source code to my project at my GitHub account - https://github.com/martin-rohwedder/movstream
您可以在我的GitHub帐户上查看我项目的完整源代码-https: //github.com/martin-rohwedder/movstream
Is 'EnterMovieDetails' really the id of one of your view? “ EnterMovieDetails”是否真的是您其中一个视图的ID? (if you could post you WebFlow config file, that'd be helpful).
(如果您可以发布WebFlow配置文件,那将会很有帮助)。
If you use SWF 2, please have a look at the paragraph 4.10 of the documentation . 如果使用SWF 2,请参阅文档的 4.10段。
You first need to make sure that your validation method contains the view id in its name. 首先,您需要确保验证方法的名称中包含视图ID。
Also, I don't think you need to use a bind tag in your JSP around your error tag. 另外,我认为您不需要在JSP中的错误标记周围使用绑定标记。
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.