You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christian Traber <ch...@traber-net.de> on 2003/05/06 17:06:38 UTC

empty HTML-Form after validator fail

Hi,

I have a ValidatorForm with simple validation rules to check if fields 
are empty...
If one validation rule fails, back at my jsp form all fields are empty!
How can I rescue the already filled out  field values?

I fill the from from another Bean in request scope (not the ValidatorForm!):
<jsp:useBean id="UserData2Edit" class="de.traber.UserData" scope="request"/>
...
 <html:form action="/UserData.do" method="POST">
...
    <html:text styleClass="entry" name="UserData2Edit" property="username"/>
...
...

Is there the problem, howelse can I fill the form for editing?

Thanks and regards,
Christian


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: empty HTML-Form after validator fail

Posted by Robert Taylor <rt...@mulework.com>.
Ah ha! I think I understand now. It sounds like your form.reset()
is overwritting your user input. Populate the form in the set up edit
_action_ (not the form.reset()) then forward to the page.

Struts will invoke form.reset() which will
clear the form and then populate it with information in the request
parameters.

When validation fails, Struts will forward back to the input page where the
<html:form ../> will "find" the form in the request and re-render it.

If you have drop down lists in your form that need to be populated, then
you will need to do this in form.reset() unless you cache that data in
ServletContext.

robert
> -----Original Message-----
> From: Christian Traber [mailto:christian@traber-net.de]
> Sent: Tuesday, May 06, 2003 4:03 PM
> To: Struts Users Mailing List
> Subject: Re: empty HTML-Form after validator fail
>
>
> Thanks Robert,
>
> but now I found out that what you suggest is my problem;-)
> I have a action to populate my form and I can get the values
> before editing,
> but so all edited fields are reset to previos values.
>
> Whatelse can I do?
> I have the new values in the validate method but how can I pass them to
> my populate action?
>
> Regards,
> Christian
>
>
>
> Robert Taylor wrote:
>
> >Christian,
> >
> >since your form is populated by a bean in request scope.
> >That bean (and its accompanying data) is gone after you submit
> >the form for processing. When validation fails, Struts will forward
> >to the url defined in the "input" attribute of the action element in
> >struts-config file. If that value is the actual page, then the request
> >is forwarded back to the page where the jsp:userBean attempts to find
> >the bean in request scope. Since the bean is not there, it creates a new
> >bean with empty data. So your form data (which exists in the forwarded
> >request) is being overwritten with empty data in the UserData bean.
> >
> >I might suggest that you have a set up action that populates the form
> >before displaying the page. Have your set up action populate the form
> >with UserData (use BeanUtils). Then if validation fails, the request is
> >forwarded back to the page where user input will be re-rendered as it
> >was entered.
> >
> >hth,
> >
> >robert
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: empty HTML-Form after validator fail

Posted by Christian Traber <ch...@traber-net.de>.
Thanks Robert,

but now I found out that what you suggest is my problem;-)
I have a action to populate my form and I can get the values before editing,
but so all edited fields are reset to previos values.

Whatelse can I do?
I have the new values in the validate method but how can I pass them to 
my populate action?

Regards,
Christian



Robert Taylor wrote:

>Christian,
>
>since your form is populated by a bean in request scope. 
>That bean (and its accompanying data) is gone after you submit
>the form for processing. When validation fails, Struts will forward
>to the url defined in the "input" attribute of the action element in
>struts-config file. If that value is the actual page, then the request
>is forwarded back to the page where the jsp:userBean attempts to find
>the bean in request scope. Since the bean is not there, it creates a new
>bean with empty data. So your form data (which exists in the forwarded
>request) is being overwritten with empty data in the UserData bean.
>
>I might suggest that you have a set up action that populates the form
>before displaying the page. Have your set up action populate the form
>with UserData (use BeanUtils). Then if validation fails, the request is
>forwarded back to the page where user input will be re-rendered as it
>was entered.
>
>hth,
>
>robert
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: empty HTML-Form after validator fail

Posted by Robert Taylor <rt...@mulework.com>.
Christian,

since your form is populated by a bean in request scope. 
That bean (and its accompanying data) is gone after you submit
the form for processing. When validation fails, Struts will forward
to the url defined in the "input" attribute of the action element in
struts-config file. If that value is the actual page, then the request
is forwarded back to the page where the jsp:userBean attempts to find
the bean in request scope. Since the bean is not there, it creates a new
bean with empty data. So your form data (which exists in the forwarded
request) is being overwritten with empty data in the UserData bean.

I might suggest that you have a set up action that populates the form
before displaying the page. Have your set up action populate the form
with UserData (use BeanUtils). Then if validation fails, the request is
forwarded back to the page where user input will be re-rendered as it
was entered.

hth,

robert

> -----Original Message-----
> From: Christian Traber [mailto:christian@traber-net.de]
> Sent: Tuesday, May 06, 2003 11:07 AM
> To: Struts Users Mailing List
> Subject: empty HTML-Form after validator fail
> 
> 
> Hi,
> 
> I have a ValidatorForm with simple validation rules to check if fields 
> are empty...
> If one validation rule fails, back at my jsp form all fields are empty!
> How can I rescue the already filled out  field values?
> 
> I fill the from from another Bean in request scope (not the 
> ValidatorForm!):
> <jsp:useBean id="UserData2Edit" class="de.traber.UserData" 
> scope="request"/>
> ...
>  <html:form action="/UserData.do" method="POST">
> ...
>     <html:text styleClass="entry" name="UserData2Edit" 
> property="username"/>
> ...
> ...
> 
> Is there the problem, howelse can I fill the form for editing?
> 
> Thanks and regards,
> Christian
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org