Results 1 to 5 of 5
  1. #1
    arfatkhan is offline Member
    Join Date
    Jul 2007
    Posts
    9
    Rep Power
    0

    Default ActionForm and Dynaform

    Hi Everybody,

    What is the difference between ActionForm and DynaFrom.

  2. #2
    tommy is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default

    f you are using actionform then you should specify the getter and setter for each components of presentation (jsp ) in to FormBean file.So it is some what complicated one to specify each component for setter and header. To avoid this method we are having DynoActionForm.In struts-config.xml file we can specify the properties.

  3. #3
    Swamipsn is offline Member
    Join Date
    Jul 2007
    Posts
    74
    Rep Power
    0

    Default

    Hi,

    ActionForm is a normal FormBean which we have to write a java bean code
    using traditional getter() & setter() and need to compile. After the rapid evolution of struts many struts developers feels that writing a java ActionFormfor every form is a tedious task. So DynaActionForm was introduced in the case of DynaActionForm we no need to write any ActionForm with native java bean code.DynaActionForm is too easy to use!!

  4. #4
    arfatkhan is offline Member
    Join Date
    Jul 2007
    Posts
    9
    Rep Power
    0

    Default

    Hi,

    I am not clear with, please explain me with a simple example.

    Thanks.
    Last edited by arfatkhan; 08-01-2007 at 12:18 PM.

  5. #5
    leonard is offline Member
    Join Date
    Jul 2007
    Posts
    43
    Rep Power
    0

    Default

    Action form example
    Java Code:
    public class AddressForm extends ActionForm
    {
      private String name=null;
      private String address=null;
      private String emailAddress=null;
    
      public void setName(String name){
        this.name=name;
      }
    
      public String getName(){
        return this.name;
      }
    
      public void setAddress(String address){
        this.address=address;
      }
    
      public String getAddress(){
        return this.address;
      }
    
    
      public void setEmailAddress(String emailAddress){
        this.emailAddress=emailAddress;
      }
    
      public String getEmailAddress(){
        return this.emailAddress;
      }
    If you pay attention in action form you have to write the set and get of every attribute

    AddressAction.java
    Java Code:
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    
    public class AddressAction extends Action
    {
      public ActionForward execute(
        ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) throws Exception{
          return mapping.findForward("success");
      }
    }
    Now, Dynaform

    Java Code:
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.DynaActionForm;
    import org.apache.struts.action.ActionMessages;
    import org.apache.struts.action.ActionMessage;
    
    
    public class AddressDynaAction extends Action
    {
      public ActionForward execute(
        ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) throws Exception{
    
        DynaActionForm addressForm = (DynaActionForm)form;
    
        //Create object of ActionMesssages
            ActionMessages errors = new ActionMessages();
        //Check and collect errors
            if(((String)addressForm.get("name")).equals("")) {
             errors.add("name",new ActionMessage("error.name.required"));
            }
    
            if(((String)addressForm.get("address")).equals("")) {
             errors.add("address",new ActionMessage("error.address.required"));
            }
    
            if(((String)addressForm.get("email")).equals("")) {
             errors.add("email",new ActionMessage("error.emailaddress.required"));
            }
        //Saves the error
        saveErrors(request,errors);
        //Forward the page
        if(errors.isEmpty()){
        return mapping.findForward("success");
        }else{
        return mapping.findForward("invalid");
        }
      }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •