You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nishit Trivedi <ni...@insage.com> on 2001/04/02 20:02:44 UTC

relation between "validate", validate method and perform method

hi..
( sorry if this is dumb que....)

Can any body tell me what is the relation between these three
1. "validate" parameter of Action mapping definition in struts-config file
2.  the "validate" method of a form bean and 
3.  a "perform" method of any class extended from Action class

Because i have the scenario: I have a form which is supposed to be validated
and then control should be
forwarded to the page depending on the value returned by "validate" method
of form bean...But i think physical
implementation of forwarding control is decided by "perform" method...right?

Here is my problem:
When the parameter "validate" in struts-config file is true, the "validate"
method of form bean class is executed but
"perform" method is not getting executed...If i switch the value of
"validate" parameter to false, the validate method
is not executed but the perform method is executed...

I don't know...what am i doing wrong?...what to do to get both of them
executed?...
Here is the snippet of my struts-config file...

<action-mappings>
...
<!-- form processing -->
    <action    path="/myForm"
               type="org.apache.struts.dir1.dir2.TestClass"
               name="MyForm"
              scope="request"
           validate="true">
      <forward name="success"              path="/success.jsp"/>
      <forward name="failure"              path="/Error.jsp"/>
    </action>
<!----------------------------------->
....
</action-mappings>

Nishit Trivedi
Software Engineer
Planet Access Networks - An InSage Company
973-691-4704 X157


Re: relation between "validate", validate method and perform method

Posted by David Winterfeldt <dw...@yahoo.com>.
If validate is set to true in the struts-config.xml,
then the ActionServlet will automatically call the
validate method in your ActionForm for you.  If there
are errors, it will return you to your input
attribute's URL.  If there aren't any errors, it will
call your perform method.  If you need to forward your
form to different pages based on the validation, you
should have validate="false" and just call the
validate method yourself inside your perform method.

public ActionForward perform(ActionMapping mapping,
			     ActionForm form,
			     HttpServletRequest request,
			     HttpServletResponse response)
  throws IOException, ServletException {

   ActionErrors errors = form.validate(mapping,
request);
   
   if (errors != null && errors.empty()) {
      return mapping.findForward("success");	
   } else if (errors.size("lastName") > 0) {
      return mapping.findForward("failureLastName");
   } else {
      return mapping.findForward("failure");
   }
}



David

--- Nishit Trivedi <ni...@insage.com> wrote:
> hi..
> ( sorry if this is dumb que....)
> 
> Can any body tell me what is the relation between
> these three
> 1. "validate" parameter of Action mapping definition
> in struts-config file
> 2.  the "validate" method of a form bean and 
> 3.  a "perform" method of any class extended from
> Action class
> 
> Because i have the scenario: I have a form which is
> supposed to be validated
> and then control should be
> forwarded to the page depending on the value
> returned by "validate" method
> of form bean...But i think physical
> implementation of forwarding control is decided by
> "perform" method...right?
> 
> Here is my problem:
> When the parameter "validate" in struts-config file
> is true, the "validate"
> method of form bean class is executed but
> "perform" method is not getting executed...If i
> switch the value of
> "validate" parameter to false, the validate method
> is not executed but the perform method is
> executed...
> 
> I don't know...what am i doing wrong?...what to do
> to get both of them
> executed?...
> Here is the snippet of my struts-config file...
> 
> <action-mappings>
> ...
> <!-- form processing -->
>     <action    path="/myForm"
>               
> type="org.apache.struts.dir1.dir2.TestClass"
>                name="MyForm"
>               scope="request"
>            validate="true">
>       <forward name="success"             
> path="/success.jsp"/>
>       <forward name="failure"             
> path="/Error.jsp"/>
>     </action>
> <!----------------------------------->
> ....
> </action-mappings>
> 
> Nishit Trivedi
> Software Engineer
> Planet Access Networks - An InSage Company
> 973-691-4704 X157
> 


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/?.refer=text