struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mohan Radhakrishnan" <mradhakrish...@cellexchange.com>
Subject RE: Populating select boxes dynamically
Date Tue, 08 Jul 2003 14:25:02 GMT

         If it is only countries then you can load it when the application
starts up. You have to implement ServletContextListener. You will have a
data base call in your class that implements this interface.

          A 'prepopulate' action is like any other normal action that does
something and forwards to the right view.

Mohan

-----Original Message-----
From: Sandeep Takhar [mailto:sandeep_takhar@yahoo.com]
Sent: Tuesday, July 08, 2003 6:15 PM
To: Struts Users Mailing List
Subject: RE: Populating select boxes dynamically


I would store something like this in application
context.  This is easier in your case since you have
one language it seems.

PreActions can be created simply by having a
BaseAction that everything overrides.

The baseAction has a bunch of hooks that can be
overridden.  One of these is
preProcessing(mapping,request,response,form).

A good resource is Ted Husted's book (Struts in
Action)

Someone else may have more details...

sandeep

--- sriram <sriram@nunet-tech.com> wrote:
> James,
>
> As explained by you, I have done the following:
>
> I need list of countries in a drop-down box in .jsp
> page.
>
> I have an EJB that maps to country table in
> database.
> In that I've a method getAllCountries() that returns
> a collection.
> In that method, I've used LabelValueBean and storing
> labels and values in the collection.
>
> I'm using a Session Fagade, so this method is called
> by a session bean which obtains the collection of
> countries.
>
> Now I would like to know the next step - creating a
> "pre" action which obtains this collection and
> stores it in 'request'.
> I've an action form with getter and setter methods
> for 'countryID' (countryID is the name of my
> <html:select> in the jsp page). But how to create a
> "pre" action? Can you pl. explain?
>
> Thanks
> Sriram
>
> -----Original Message-----
> From: James Childers [mailto:jchilders@hotels.com]
> Sent: Tuesday, July 01, 2003 6:51 PM
> To: Struts Users Mailing List
> Subject: RE: Populating select boxes dynamically
>
>
> > -----Original Message-----
> > From: sriram [mailto:sriram@nunet-tech.com]
> > Sent: Tuesday, July 01, 2003 4:18 AM
> > To: 'struts-user@jakarta.apache.org'
> > Subject: Populating select boxes dynamically
> >
> > I am fairly new to struts. I am using struts 1.0.
> I have
> > couple of list boxes in my input form which need
> to populated
> > with data retrieved from the database.
> >
> > What is the process to be followed? Can somebody
> give me
> > links to related examples on the net?
>
> Hi Sriram,
>
> This is pretty easy. You should read up on the
> Struts JavaDocs for LabelValueBean:
>
>
http://jakarta.apache.org/struts/api/org/apache/struts/util/LabelValueBean.h
tml
>
> As well as for the <html:options> tag:
>
>
http://jakarta.apache.org/struts/api/org/apache/struts/taglib/html/OptionsTa
g.html
>
> Since you're using 1.0 I *think* you'll need to grab
> the source for that bean and add it to your project,
> but you'll want to do this anyway because it is
> extremely helpful (and pretty simple insofar as
> beans go).
>
> What you'll do at that point is add the elements
> which will be used in your select box in a "pre"
> Action, which will add these LabelValueBeans to a
> Colletion, which will in turn be added to the
> request.
>
> Clear as mud? Maybe this will help:
>
> 1) Create a "pre" Action, which will prepare the
> data for the JSP which has the select box.
>
> 2) In this Action, do your database operations and
> store each result in a LabelValueBean. It will look
> something like this:
> 	List aList = new ArrayList();
> 	while (rs.next()) {
> 		LabelValueBean lvb = new
> LabelValueBean(rs.getString("labelCol"),
> rs.getString("valueCol"));
> 		aList.add(lvb);
> 	}
> 	// Now, add it to the request so we can see it in
> our JSP
> 	request.setAttribute("yerSelectBox", aList);
>
> 3) In your JSP, you'll just (hopefully!) need to
> reference the List you added to request scope using
> the <html:options> tag:
> 	<html:select property="anActionFormElement">
> 		<html:options collection="yerSelectBox"
> property="value" labelProperty="label" />
> 	</html:select>
>
> HTH,
>
> -= James
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
>


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message