File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes how to pre-populate a form? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to pre-populate a form?" Watch "how to pre-populate a form?" New topic
Author

how to pre-populate a form?

Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
I am wondering what a good way is to pre-populate a form? For example, if I submit form1 to actionclass1, and actionclass1 forwards to form2, how can I pre-populate fields on form2 before it is rendered?

Thanks!
swatione chowdary
Greenhorn

Joined: Apr 07, 2005
Posts: 27
put the first form bean in session.

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {

HttpSession session=request.getSession();
session.setAttribute( "theName", form );
return mapping.findForward("success");
}

and in second form bean class reset method type cast the form bean by calling getattribute method. and set all the values like this.

public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub


if(this.getMfirstName()==null){
UserCreationForm frm=(UserCreationForm)request.getSession().getAttribute("theName");

if(frm!=null){
this.setMfirstName(frm.getFirstName());
this.setMmiddleInitial(frm.getMiddleInitial());
this.setMlastName(frm.getLastName());
this.setMidNumber(frm.getidNumber());
this.setMaddress1(frm.getAddress1());
this.setMaddress2(frm.getAddress2());
this.setMcity(frm.getCity());
this.setMpostalCode(frm.getPostalCode());
this.setMphoneNumber(frm.getPhoneNumber());
}
}


am i correct in solution.



swati.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to pre-populate a form?