There are various solutions.
I put a hidden variable on my form (& in the formBean) with the form name in
it.
If it's not there I know not to validate the form data.
Some people have 2 Actions & Action classes for this but I fear that would lead
to too much code duplication.
However some of my Action classes are getting a bit big & unwieldy.

--- "Pritchard, Sean" <[EMAIL PROTECTED]> wrote:
> I've run into a bit of a sticking point on form validation and I'm wondering
> whether anyone else has encountered this.  I have an Action EditUserAction
> that works with a UserForm to edit a user's data (e.g. first name, last
> name. email, etc.).  In my Action, I check the request for a valid token.
> If the token is not valid, I get the user's data from the database (via the
> model layer) and populate the form with it.  I then forward control to a jsp
> that displays the form.  If the token is valid, I update the user's data in
> the database (again via the model layer) with the data in the form.  So I
> use the same Action to initially populate the form and then to process the
> submitted form.
> 
> The problem I'm running into, is that I want to begin using form validation.
> So I created a validate method that ensures the email address is not null or
> zero-length.  The problem is, that the error message is displayed the first
> time the form is displayed (i.e. before the form is submitted).  It seems I
> should only validate the form when it is submitted rather than the first
> time it is displayed.  It is currently being validated before the user
> submits it, so if the user has not previously submitted an email address,
> when they first see the form, the error message "Email address is required"
> appears.  
> 
> My current design would call for the form validation to be invoked only when
> the token is valid.  But Struts doesn't seem to lend itself to validating a
> token within a form (because the token validation methods are protected
> instance methods of Action).  It feels a bit like I'm fighting the direction
> the framework wants to go, which makes me think my design is flawed.  Any
> suggestions?  Should I use two separate actions, one to populate the form
> and one to process the submit?  That would allow me to set validation on one
> and not the other.  Should I check for a valid token inside my validate()
> method and only look for errors if the token is valid?  
> 
> Thanks in advance for your suggestions.
> Sean
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 


=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Search the archive:-
http://www.mail-archive.com/struts-user%40jakarta.apache.org/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Bacon - Looking for struts work - South-East UK.
phone UK 07960 011275

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to