Results 1 to 5 of 5
Thread: ActionForm and Dynaform
- 07-31-2007, 01:40 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 9
- Rep Power
- 0
- 07-31-2007, 02:07 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
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.
- 07-31-2007, 02:11 PM #3
Member
- Join Date
- Jul 2007
- Posts
- 74
- Rep Power
- 0
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!!
- 08-01-2007, 11:31 AM #4
Member
- Join Date
- Jul 2007
- Posts
- 9
- Rep Power
- 0
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.
- 08-09-2007, 11:06 PM #5
Member
- Join Date
- Jul 2007
- Posts
- 43
- Rep Power
- 0
Action form example
If you pay attention in action form you have to write the set and get of every attributeJava 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; }
AddressAction.java
Now, DynaformJava 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"); } }
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"); } } }


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks