PDA

View Full Version : Strange setup bean behaviour with validation



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&#58;/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&#58;/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&#58;out value="$&#123;flowExecutionId&#125;"/>">

<%-- Spring tags to bind the entered values automatically to bean attributes and to print error messages --%>

<TABLE border="0">

<tr>
<td>
<spring&#58;bind path="formBean.login">
<input type="text" name="<c&#58;out value="$&#123;status.expression&#125;" />" value="<c&#58;out value="$&#123;status.value&#125;" />"/>
<DIV style="color&#58;red">
<c&#58;forEach var="error" items="$&#123;status.errorMessages&#125;"><li><c&#58;out value="$&#123;error&#125;" /></li></c&#58;forEach>
</DIV>
</spring&#58;bind>
</td>
</tr>
<tr>
<td>
<spring&#58;bind path="formBean.password">
<input type="password" name="<c&#58;out value="$&#123;status.expression&#125;" />" value="<c&#58;out value="$&#123;status.value&#125;" />"/>
<DIV style="color&#58;red">
<c&#58;forEach var="error" items="$&#123;status.errorMessages&#125;"><li><c&#58;out value="$&#123;error&#125;" /></li></c&#58;forEach>
</DIV>
</spring&#58;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&#40;Object obj, Errors errors&#41; &#123;
LoginFormBean loginData = &#40;LoginFormBean&#41;obj;
validateLoginAndPassword&#40;loginData, errors&#41;;
&#125;

private void validateLoginAndPassword&#40;LoginFormBean loginData, Errors errors&#41; &#123;
LogFactory.getLogger&#40;this&#41;.debug&#40;"Validating login data"&#41;;

ValidationUtils.rejectIfEmptyOrWhitespace&#40;errors,"login",null,"Please specify your login name"&#41;;
ValidationUtils.rejectIfEmptyOrWhitespace&#40;errors,"password",null,"Please specify your password"&#41;;

&#125;
...


Any ideas?

Chris

Christian
Jun 18th, 2005, 10:49 AM
Damn it, just stumbled across this line in the Preview 4 - Completed Changes change log:



Fixed problem with 'form states': view states that use a setup action and a bindAndValidate when transitioning out of the state. The validation errors generated by the bindAndValidate were being overwritten by the setupForm action when the view state re-entered.

think that's it, i will download the latest version from the CVS now and try again.[/quote]

klr8
Jun 18th, 2005, 12:55 PM
Note that SWF has moved out of the spring sandbox and is now in its own repository (spring-projects/spring-webflow) at SourceForge (http://cvs.sourceforge.net/viewcvs.py/springframework/spring-projects/spring-webflow/).

The migration is still in progress. In particular the Portlet related code has yet to find a new home.

Anyway, to build it, you have to pull in ALL the sub-modules of "spring-projects". Once that is done, you can do "build dist" in the spring-webflow module to build a SWF jar that you can use with the existing webflow-support.jar.

Erwin

Christian
Jun 20th, 2005, 04:58 AM
Is there a complete PR4 jar in the CVS? I've checked out the whole spring-projects in Eclipse and then tried to run the build.xml file in the spring-webflow folder. The build fails with the following error message:

common-targets.xml: 297: Unable to find typedef antlib:fr.jayasoft.ivy.ant:resolve

If there is a quick fix for this or a description of how to build the project with Eclipse please post an answer. Otherwise I will wait for PR4 :( .

Christian

Keith Donald
Jun 20th, 2005, 05:27 PM
You're on the right track. The new build system using ivy for dependency management. To build successfully from ant, you need ivy-1.1.jar in your ant classpath.