You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peter Valencic <pe...@in2.si> on 2007/05/23 16:18:33 UTC

prepopulating a form (how to prepopulate ActionForm before it is called)

Hello to all.

I would like to populate a ActionForm bean ..
for example

I have 2 pages

page A.jsp and page B.jsp on page A I have ActionForm and on page B I 
have ActionForm bean..

Is there a possibility to prepopulate ActionForm for page B from page A?

example

  *public* ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) *throws* IOException, ServletException
   {
      System.out.println("Action 1");
      HttpSession ses = request.getSession(*true*);
      System.out.println(ses.getId());
    
      
      Abean bean = (Abean)form;
      Bbean bbean = *new* Bbean();
      bbean.setIme("Franko");
      
      ses.setAttribute("Bbean",bbean);
       *return* mapping.findForward("success");
   }



then on page B.jsp i display datas:

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ page contentType="text/html;charset=windows-1250"%>
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<title>untitled</title>
</head>
<body>
 <html:form action="action2.do" scope="session">
  <P>To je B stran</P>
  <P>to je:
    <bean:write name="Abean" property="ime" scope="session"/> 
 
    <html:text property="ime"></html:text>
    <html:submit/>
  </html:form>
</body>
</html>
 




ABean is ActionForm for page A.jsp and Bbean is ActionForm bean from 
page B.jsp

what I like to do is to set some parameters which will be displayed when 
page B will be called...

I'dont know is this what I have do is ok? I have develped a large 
project for car assicuration but when many users acess the page some of 
them get null values or exceptions (maybe I'am not doing it in the right 
way)?

from the real life...

On page A user must enter a policy number...
Then the ActionForm for page A is called... in this action I acess the 
database and read some datas... With this datas i would like to 
prepopulate the page B so I declare a new bean which is ActionForm from 
page B and prepopulate it with some values... Then I store te bean in 
session variable.....

is this the right way? Anybody can give me some example?

best regards