Christian
Jun 18th, 2005, 10:43 AM
Hi,
I've stumbeld across a strange behaviour of the new setup bean action element when it is used togehter with validation. Don't know if it's a bug or if I do something wrong(which might be more probable ) 8).
When I define my workflows with the new setup bean action element and the form is redisplayed for correction because a validation error occured, no error messages are shown. When I replace the setup bean action with a "normal" action state for the setupForm method of my FormAction, error messages are shown correctly.
Here is the code:
The flow definition that doesn't work:
<webflow id="loginFlow" start-state="loginForm. view">
<view-state id="loginForm.view" view="loginForm">
<setup bean="flow.login.LoginAction" method="setupForm"/>
<transition on="submit" to="launch.project.flow">
<action bean="flow.login.LoginAction" method="bindAndValidate"/>
</transition>
<transition on="error" to="loginForm.view"/>
</view-state>
<end-state id="launch.project.flow" view="redirect:/flowController?_flowId=projectFlow"/>
</webflow>
The working definition:
<webflow id="loginFlow" start-state="setupForm.action">
<action-state id="setupForm.action">
<action bean="flow.login.LoginAction" method="setupForm"/>
<transition on="success" to="loginForm.view"/>
</action-state>
<view-state id="loginForm.view" view="loginForm">
<transition on="submit" to="launch.project.flow">
<action bean="flow.login.LoginAction" method="bindAndValidate"/>
</transition>
<transition on="error" to="loginForm.view"/>
</view-state>
<end-state id="launch.project.flow" view="redirect:/flowController?_flowId=projectFlow"/>
</webflow>
the JSP page:
<FORM method="POST" action="flowController" >
<%-- needed to keep track of the flow-status of the client --%>
<INPUT type="hidden" name="_flowExecutionId" value="<c:out value="${flowExecutionId}"/>">
<%-- Spring tags to bind the entered values automatically to bean attributes and to print error messages --%>
<TABLE border="0">
<tr>
<td>
<spring:bind path="formBean.login">
<input type="text" name="<c:out value="${status.expression}" />" value="<c:out value="${status.value}" />"/>
<DIV style="color:red">
<c:forEach var="error" items="${status.errorMessages}"><li><c:out value="${error}" /></li></c:forEach>
</DIV>
</spring:bind>
</td>
</tr>
<tr>
<td>
<spring:bind path="formBean.password">
<input type="password" name="<c:out value="${status.expression}" />" value="<c:out value="${status.value}" />"/>
<DIV style="color:red">
<c:forEach var="error" items="${status.errorMessages}"><li><c:out value="${error}" /></li></c:forEach>
</DIV>
</spring:bind>
</td>
</tr>
<TR>
<TD colspan="2" align="right">
<%-- _eventId is used to choose the next transition --%>
<INPUT type="submit" value="submit" name="_eventId"></TD>
</TR>
</TABLE>
</FORM>
My Validator:
...
public void validate(Object obj, Errors errors) {
LoginFormBean loginData = (LoginFormBean)obj;
validateLoginAndPassword(loginData, errors);
}
private void validateLoginAndPassword(LoginFormBean loginData, Errors errors) {
LogFactory.getLogger(this).debug("Validating login data");
ValidationUtils.rejectIfEmptyOrWhitespace(errors,"login",null,"Please specify your login name");
ValidationUtils.rejectIfEmptyOrWhitespace(errors,"password",null,"Please specify your password");
}
...
Any ideas?
Chris
I've stumbeld across a strange behaviour of the new setup bean action element when it is used togehter with validation. Don't know if it's a bug or if I do something wrong(which might be more probable ) 8).
When I define my workflows with the new setup bean action element and the form is redisplayed for correction because a validation error occured, no error messages are shown. When I replace the setup bean action with a "normal" action state for the setupForm method of my FormAction, error messages are shown correctly.
Here is the code:
The flow definition that doesn't work:
<webflow id="loginFlow" start-state="loginForm. view">
<view-state id="loginForm.view" view="loginForm">
<setup bean="flow.login.LoginAction" method="setupForm"/>
<transition on="submit" to="launch.project.flow">
<action bean="flow.login.LoginAction" method="bindAndValidate"/>
</transition>
<transition on="error" to="loginForm.view"/>
</view-state>
<end-state id="launch.project.flow" view="redirect:/flowController?_flowId=projectFlow"/>
</webflow>
The working definition:
<webflow id="loginFlow" start-state="setupForm.action">
<action-state id="setupForm.action">
<action bean="flow.login.LoginAction" method="setupForm"/>
<transition on="success" to="loginForm.view"/>
</action-state>
<view-state id="loginForm.view" view="loginForm">
<transition on="submit" to="launch.project.flow">
<action bean="flow.login.LoginAction" method="bindAndValidate"/>
</transition>
<transition on="error" to="loginForm.view"/>
</view-state>
<end-state id="launch.project.flow" view="redirect:/flowController?_flowId=projectFlow"/>
</webflow>
the JSP page:
<FORM method="POST" action="flowController" >
<%-- needed to keep track of the flow-status of the client --%>
<INPUT type="hidden" name="_flowExecutionId" value="<c:out value="${flowExecutionId}"/>">
<%-- Spring tags to bind the entered values automatically to bean attributes and to print error messages --%>
<TABLE border="0">
<tr>
<td>
<spring:bind path="formBean.login">
<input type="text" name="<c:out value="${status.expression}" />" value="<c:out value="${status.value}" />"/>
<DIV style="color:red">
<c:forEach var="error" items="${status.errorMessages}"><li><c:out value="${error}" /></li></c:forEach>
</DIV>
</spring:bind>
</td>
</tr>
<tr>
<td>
<spring:bind path="formBean.password">
<input type="password" name="<c:out value="${status.expression}" />" value="<c:out value="${status.value}" />"/>
<DIV style="color:red">
<c:forEach var="error" items="${status.errorMessages}"><li><c:out value="${error}" /></li></c:forEach>
</DIV>
</spring:bind>
</td>
</tr>
<TR>
<TD colspan="2" align="right">
<%-- _eventId is used to choose the next transition --%>
<INPUT type="submit" value="submit" name="_eventId"></TD>
</TR>
</TABLE>
</FORM>
My Validator:
...
public void validate(Object obj, Errors errors) {
LoginFormBean loginData = (LoginFormBean)obj;
validateLoginAndPassword(loginData, errors);
}
private void validateLoginAndPassword(LoginFormBean loginData, Errors errors) {
LogFactory.getLogger(this).debug("Validating login data");
ValidationUtils.rejectIfEmptyOrWhitespace(errors,"login",null,"Please specify your login name");
ValidationUtils.rejectIfEmptyOrWhitespace(errors,"password",null,"Please specify your password");
}
...
Any ideas?
Chris