• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

how to pre-populate a form?

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dinner will be steamed monkey heads with a side of tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic