Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Help: Populate DB Data into FormBean

Davis, John (Lynch)

2007-03-12


Hi all,

I'm just getting started with Struts 1.3.x and I've run into a problem I
just can't seem to find a way to tackle. I am simply trying to load data
from a database and populate it in a form-bean.

The flow is like this:

   1. user logs in

   2. authenticate user

   3. display a main form with user specific data in
<html:select>

If I do static initialization of data in the ActionForm, the data shows
up just as I would expect.

My question is, where do I need to load the information and how do I
inject it into the form-bean object.

Skipping the jdbc connectivity at this point, I have tried the
following:

   public ActionForward execute(ActionMapping mapping,
ActionForm form,

   HttpServletRequest request, HttpServletResponse
response)

   throws Exception {

   BuildMainForm bmf = (BuildMainForm)form;

   ArrayList builds = new ArrayList();

   builds.add(new LabelValueBean("build 1", "build 1"));

   builds.add(new LabelValueBean("build 2", "build 2"));

   builds.add(new LabelValueBean("build 3", "build 3"));

   bmf.setBuilds(builds);

   

   return mapping.findForward("Success");

   } // End execute()

I tried putting this in my LoginAction class to no effect, and I have
put it in my MainAction class. Since my current forward action for my
main class just goes back to main, if I do click submit and get
forwarded back to the same page, the options do appear in my drop down.

I have the following tags in my jsp:

   <html:select property="buildNameOld">

   <html:optionsCollection property="builds"/>

   </html:select>

and from my struts-config.xml

   <form-bean

   name="loginForm"

   type="LoginForm"/>

   <form-bean

   name="buildMainForm"

   type="BuildMainForm" />

   <action path="/login"

   type="LoginAction"

   name="loginForm"

   scope="request"

   validate="false"

   input="/login.jsp">

   <forward name="Success" path="/build_main.jsp" />

   <forward name="Fail" path="/login_fail.jsp" />

   </action>

   <action path="/build_main"

   type="BuildMainAction"

   name="buildMainForm"

   scope="request"

   validate="false" >

   <forward name="Success" path="/build_main.jsp" />

   <forward name="Fail" path="/login_fail.jsp" />

   </action>

Any guidance on this would be greatly appreciated.

Thanks,

Lynch

©2008 junlu.com - Jax Systems, LLC, U.S.A.