Question

I am trying to create Spring web flow application. I have following situation:

flow1.xml

<var name="user" class="com.test.User" />

<view-state id="signup" model="user">
    <transition on="loginCredentialsEntered" to="lookupUser" />
</view-state>

 <decision-state id="lookupUser">
    <if test="myActionBean.lookupUser(user)"
        then="userRegistered" else="registerUser" />
</decision-state>

signup.jsp:

<html xmlns:form="http://www.springframework.org/tags/form">
<body>
    <form action="&_eventId=loginCredentialsEntered" method="post"> 
        <input type="hidden" name="_flowExecutionKey" value=""/>
        <table>
            <tr>
                <td>Login Name:</td>
                <td><input type="text" name="loginName"/></td>
            </tr>
         </table>
        <input type="submit" value="Login" />
    </form>
</body>
</html>

Inside method myActionBean.lookupUser(user), I can see that user.loginName is being passed which was entered in the form.

However, if I use link instead of button to submit the form

<a href="${flowExecutionUrl}&_eventId=loginCredentialsEntered">Login</a>

I can see that user.loginName is null.

Can anybody explain me the reason and workaround

Thanks in advance

Was it helpful?

Solution 2

If you're replacing the button with an anchor, then you're no longer submitting the form? Clicking the link won't send the loginName parameter - because it's not submitting the form.

If you want to replace the button with a link, then you'd need to use Javascript to submit the form when you click the link.

Give the form a name:

<form name="myForm" action="${flowExecutionUrl}&_eventId=loginCredentialsEntered" 
                                                         method="post"> 

And modify the link to:

<a href="#" onclick="document.myForm.submit();">Login</a>

Alternatively, a better solution would be to leave the button and use CSS to style it more like a link. Then there would be no Javascript needed.

OTHER TIPS

That's because the form is submitted to nowhere.
Change the Form tag to:

<form action="${flowExecutionUrl}&_eventId=loginCredentialsEntered" 
                                                         method="post"> 

and it'll work.

By the way, you shouldn't pass parameters using the URL like this, better do the same thing you do with _flowExecutionKey:

<form action="${flowExecutionUrl}" method="post"> 
<input type="hidden" name="_eventId" value="loginCredentialsEntered" /> 
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top