Alok,

There are methods which are (can) be called before the
framework calls your action.

If you think about it, the framework collects the data
from the request for you and stores in your form bean.
This is the form which you have created with getters
and setters. However ,as part of the processing before
passing you this data in your action, it can also call
the validate and reset methods in the form.

Why does it do this ? Well you may well have asked it
to validate your data (by whatever means) by a
configuration setting for that action, and it needs to
reset the fields to give you nice clean values (this
is needed in particular for checkbox fields, but you
can ignore this for the moment.

So normally you would have a method like the following
in your form bean 

 /**
   * Validate all properties to their default values.
   * @param mapping The ActionMapping used to select
this instance.
   * @param request The HTTP Request we are
processing.
   * @return ActionErrors A list of all errors found.
   */
  public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
  {

    // Perform the validation of all the fields here
    // Non business validation only ...

If you return an empty errors object from here (look
at the return type it is ActionErrors), then the
framework knows that all is well and will pass the
form bean onto you for processing in your action.

If it is not an empty errors object , then the
framework knows that something is amiss, and does NOT
pass it on to your action, there would be no point.

So yes, there are some additionalprocessing methods
which can come in way of the form bean data being
passed to you in your action.

I hope that helps you, Colin C









 --- Alok Pota <[EMAIL PROTECTED]> wrote: > I
downloaded the latest version of Struts and I got
> the struts-blank.war to
> run. I have three files (SubmitAction, SubmitForm
> and submit.jsp) that I use
> on top of the struts-blank files. The following are
> my files:
> 
>
======================================================
> web.xml
>
======================================================
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE web-app
> 
>   PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> Application 2.2//EN"
> 
>   "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd";>
> <web-app>
>   <!-- Standard Action Servlet Configuration (with
> debugging) -->
> 
>   <servlet>
>     <servlet-name>action</servlet-name>
>    
>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
>     <init-param>
>       <param-name>application</param-name>
>      
> <param-value>ApplicationResources</param-value>
>     </init-param>
>     <init-param>
>       <param-name>config</param-name>
>      
>
<param-value>/WEB-INF/struts-config.xml</param-value>
>     </init-param>
>     <init-param>
>       <param-name>debug</param-name>
>       <param-value>2</param-value>
>     </init-param>
>     <init-param>
>       <param-name>detail</param-name>
>       <param-value>2</param-value>
>     </init-param>
>     <init-param>
>       <param-name>validate</param-name>
>       <param-value>true</param-value>
>     </init-param>
>     <load-on-startup>2</load-on-startup>
>   </servlet>
> 
>   <!-- Standard Action Servlet Mapping -->
> 
>   <servlet-mapping>
>     <servlet-name>action</servlet-name>
>     <url-pattern>*.do</url-pattern>
>   </servlet-mapping>
> 
>   <!-- Struts Tag Library Descriptors -->
> 
>   <taglib>
>    
> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
>    
>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
>   </taglib>
> 
>   <taglib>
>    
> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
>    
>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
>   </taglib>
> 
>   <taglib>
>    
> <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
>    
>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
>   </taglib>
> </web-app>
> 
>
======================================================
> struts-config.xml
>
======================================================
> 
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <!DOCTYPE struts-config PUBLIC
>           "-//Apache Software Foundation//DTD Struts
> Configuration 1.0//EN"
>          
>
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd";>
> <struts-config>
>   <!-- ========== Form Bean Definitions
> =================================== -->
>   <form-beans>
>     <form-bean name="submitForm" type="SubmitForm"/>
>   </form-beans>
>   <!-- ========== Action Mapping Definitions
> ============================== -->
>   <action-mappings>
>      <action  path="/submit"
>               type="SubmitAction"
>               name="submitForm"
>               input="/submit.jsp"
>               scope="request">
>     <forward name="success" path="/submit.jsp"/>
>     <forward name="failure" path="/submit.jsp"/>
>     </action>
>   </action-mappings>
> </struts-config>
> 
>
======================================================
> SubmitAction
>
======================================================
> import javax.servlet.http.*;
> import org.apache.struts.action.*;
> 
> public final class SubmitAction extends Action {
> 
>   public ActionForward execute(ActionMapping
> mapping, ActionForm form,
> HttpServletRequest request,HttpServletResponse
> response) {
> 
>     System.out.println("GOT
> HERE!!!!!!!!..............");
>     return (mapping.findForward("success"));
>   }
> 
> }
> 
>
======================================================
> SubmitForm
>
======================================================
> 
> import javax.servlet.http.HttpServletRequest;
> import org.apache.struts.action.*;
> 
> public final class SubmitForm extends ActionForm {
> 
>     /* Last Name */
>     private String lastName;
>     public String getLastName() {
>         return (this.lastName);
>     }
>     public void setLastName(String lastName) {
>         this.lastName = lastName;
>     }
> 
>     /* Address */
>     private String address = null;
>     public String getAddress() {
>         return (this.address);
>     }
>     public void setAddress(String address) {
>         this.address = address;
>     }
> 
>     /* Sex */
>     public String getSex() {
>         return (this.sex);
>     }
>     public void setSex(String sex) {
>         this.sex = sex;
>     }
> 
>     /* Married status */
>     private boolean married;
>     public boolean isMarried() {
>         return (this.married);
>     }
>     public void setMarried(boolean married) {
>         this.married = married;
>     }
> 
>     /* Age */
>     private String age = null;
>     public String getAge() {
>         return (this.age);
>     }
>     public void setAge(String age) {
>         this.age = age;
>     }
> }
> 
> 
> The url I use to access submit.jsp is
> http://localhost:80/app/submit.do.
> From my newbie understanding of Struts,
> /submit.do is translated to /submit which is mapped
> to the SubmitAction
> class whose execute method does some pre-processing
> b4 forwarding to the
> appropriate exit point (in this case the view).
> 
> It looks like the execute() method of SubmitAction
> does not get call
> initially. If however I give default values to all
> the fields of SubmitForm,
> the execute method gets called.
> 
=== message truncated === 

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

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

Reply via email to