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 22:48:04 UTC

RE: relation between "validate", validate method and perform meth od

thanks david...
i used this approach and its working...

Nishit

-----Original Message-----
From: David Winterfeldt [mailto:dwinterfeldt@yahoo.com]
Sent: Monday, April 02, 2001 2:33 PM
To: struts-user@jakarta.apache.org
Subject: Re: relation between "validate", validate method and perform
method


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

entity beans within an Action

Posted by "G.L. Grobe" <ga...@grobe.org>.
If the life-span of an Action is only when that Action is being exec'd
(which is also where I implemented my session bean since it's life-span is
also not neccesary to hang around), where should entity beans be initialized
and populated by data held in the ActionForm bean? Seems if I init'd them
within the Action, I'd be creating a new Bean everytime it ran through that
Action, same w/ the session. Am I going about this wrong?

Any help much appreciated.