Hi.

 

1.    What version of struts are you working with ?

2.    If the action map's validate attribute is set to true, the
form.validate() method is called *before* the action is executed. If
there are errors it will forward back to the input page (value of the
input attribute).

3.    To avoid having struts call validate for addEdit=add, you need to
either (a) forward to a different action that has validate=false or (b)
check the value of addEdit in your form and don't call the super unless
its 'edit', or (c) use one action map for add and edit and another for
submitting the changes (the latter is the one that should have
validate=true).

 

 

Note that you can have multiple actions can be mapped to the same action
class.

 

HTH,

 

Rich

 

-----Original Message-----
From: Janice [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 17, 2003 8:04 PM
To: [EMAIL PROTECTED]
Subject: validation occuring before form is loaded, why?

 

Hi Gang,

 

I was having problems getting validation to work at all.  I've read
every post on getting it to work, followed all step-by-steps, and
nothing would ever do it.  Today I yanked all the .jar files out of my
lib directory and updated it with the .jar files from the latest release
version of struts (1.1).  Well... something started to happen all right,
just not what I expected.

 

What it looks like its doing is validating my form before its even
loaded (execute() does not get called, and my print statements in
validate() show that super.validate() is returning errors.)

 

What my code is trying to do is:

1) a list of widgets are displayed.  Each widget has a link to an edit
page.  There is also an add widget option.  Both the edit and the add
call the same action with a request parameter like addEdit=add or
addEdit=edit.

 

Currently, when either of these links are clicked, I get a 'page cannot
be displayed' and my log tells me that there was a validation error.  I
don't know why validate() is being called in the first place, I have no
explicit calls to it, and didn't expect it to get run until the next
form was submitted and my struts-config.xml said validate=true.

 

2) the next step should be that the action builds the form object with
either the reset() values for an add, or a database-retrieved set of
values for an edit.  Ideally, when this form is submitted, the form
should be validated.  If I change my validate() method on my form object
to return a new ActionErrors(), then things work better, but still don't
validate.  

 

I hope this is enough information.  I can post a bunch of code if its
not.  I really appreciate any and all help, this validation stuff is
taking soooo long to get working!

 

Thanks in advance,

Janice

 

Reply via email to