问题
i am using spring-mvc(3.2.4) and spring-webflow(2.3.2) here. i define a flow like this:
<flow>
<decision-state id="check">
<if test="signupFlowAction.checkPrecondition(messageContext)" then="firstState" else="error" />
</decision-state>
<view-state id="firstState">
...
</view-state>
<view-state id="error" view="error/bad-thing-happens">
...
</view-state>
i want to check some business preconditions when the flow startup, so i using a POJO to do so.
public boolean checkPrecondition(MessageContext messageContext) {
boolean oh_snap = true;
if (oh_snap) {
MessageResolver mr1 = new MessageBuilder().fatal().defaultText("fatal message here.").build();
MessageResolver mr2 = new MessageBuilder().error().defaultText("error message here.").build();
MessageResolver mr3 = new MessageBuilder().info().defaultText("info message here.").build();
messageContext.addMessage(mr1);
messageContext.addMessage(mr2);
messageContext.addMessage(mr3);
}
return ! oh_snap;
}
this code is fine, but i do not kown how to show the messages in jsp.
spring's taglibs did't work? i tried <spring:error path="*"/>
nothing happened.
回答1:
In your JSP
file, try something like this:
<c:forEach items="${flowRequestContext.messageContext.allMessages}" var="message">
<li>
Message Source is ${message.source}
<br>
Message Text is ${message.text}
</li>
</c:forEach>
回答2:
Assuming that you've got the Spring Form taglib directive specified as follows:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
Then I think the correct syntax to use the errors tag is:
<form:errors path="*" />
来源:https://stackoverflow.com/questions/19648882/how-do-i-show-error-info-fatal-messages-in-jsp-when-i-using-spring-webflow-with