It is not a good practice to have DB calls in ur Action class. Action Class belongs to 
web tier and it should call db layer thru' Business objects via a Business delegate. 
There was a good thread couple of weeks ago on this. After the call is made to the Db 
and results are returned, u can store the list as done in the last few lines in this 
code.

Just my thoughts.
-Ranjan.

-----Original Message-----
From: Damien VIEL [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 15, 2002 11:59 AM
To: Struts Users Mailing List
Subject: Re: populating list for html:options tag within FormBean


I've created the following Action that will populate my forms :

public final class PrepareFormAction extends Action {

 public ActionForward perform(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response)
  throws IOException, ServletException {

  Locale locale = getLocale(request);
  MessageResources messages = getResources();
  String action = request.getParameter("action");

  if ("addproject".equals(action)) {
   try {
    CompanyJob companyJob = new CompanyJob();
    ArrayList listcomp = new ArrayList();

    ResultSet rs = companyJob.getAllCompany();
    while (rs.next()) {
     String name = rs.getString("comp_name");
     String id = rs.getString("comp_id");
     listcomp.add(new LabelValueBean(name,id));
    }

    request.setAttribute("listcomp", listcomp);
   } catch (SQLException sqle) {
    System.err.println("ProjectAction Error >> " + sqle);
   }
   return (mapping.findForward("addproject"));
  }
  return (mapping.findForward("error"));
 }
}

Dams
----- Original Message -----
From: "Gary Bartlett" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 15, 2002 6:27 PM
Subject: populating list for html:options tag within FormBean


> Question -
>
> I saw in an earlier post that someone was populating
> the list for an html:options tag within a FormBean.
> My question is how does the FormBean place the list
> into the context so it is available to the tag ?
>
> I realize this is a pretty basic question, but my only
> frame of reference here is the example where the jsp
> scriptlet creates the list and places it into the
> context with pageContext.setAttribute();
>
> Thanks,
>
> Gary Bartlett
>
> __________________________________________________
> Do You Yahoo!?
> LAUNCH - Your Yahoo! Music Experience
> http://launch.yahoo.com
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to