You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tim Trentham <TT...@hand.com> on 2001/07/11 22:15:37 UTC

Question about form beans and page re-population after errors

I thought I had a pretty good handle on Struts, but I've run into something
that another user mentioned in a post last month
(http://www.mail-archive.com/struts-user@jakarta.apache.org/msg09973.html)
that has me a little stumped. The other guy never got an answer, so I'm
going to try and articulate the problem as clearly as possible.

I've got a login form that is defined in the struts-config.xml like this:

<form-bean name="loginForm"
type="com.mycompany.mypackage.beans.LoginFormBean">

the action mapping is:

<action path="/login"
            type="com.mycompany.mypackage.servlets.LoginAction"
            name="loginForm"
            scope="request"
            input="/login.jsp">
 <forward name="success" path="/success.jsp"/>
</action>

Now, in login.jsp, I originally had this as my form tag:

<html:form name="loginForm" action="/login"
type="com.mycompany.mypackage.beans.LoginFormBean">
 <snip>
</html:form>

If there were errors in the form and the login.jsp page was redisplayed, the
error messages appeared, but the fields weren't re-populated.

However, after looking at the struts-example again and changing my form tag
to:

<html:form action="/login" focus="userName">
 <snip>
</html:form>

the fields do re-populate correctly. I assume that it is the removal of the
name and type attributes in the form tag. Other than being redundant, why
does including these in the form tag cause re-populating the form to fail?

Incidentally, changing the scope on the action to session also caused
re-population to occur correctly, but I didn't want to have to use session
beans for single page forms and it seemed that the other way was supposed to
work.

Thanks very much,

Tim