struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Henrique Ferreira e Silva <dhsi...@gmail.com>
Subject Re: Struts dropdown boxes
Date Wed, 02 Nov 2005 14:05:30 GMT
Neil,

A good approach for this is always having a set up action where you
load all data to be used in dropdown boxes.
You can do this with plain Actions and, what i use the most, DispatchActions.

I usually do this way:


public class MyDispatchAction extends DispatchAction {

     public ActionForward setUp(....) {
        List dd1 = loadDropDown1();
        request.setAttribute("dd1", dd1);
        if (is some form property set) {
           List dd2 = loadDropDown2(myFormProperty);
           request.setAttribute("dd2", dd2);
        }

        return mapping.findForward("go");
     }

     public ActionForward doStuff(....) {

         // do whatelse you need to
        return mapping.findForward("go");
    }

}

Then in my jsp page i have:

<html:form action="/MyDispatchAction">
   <html:hidden property="methodToCall" value="doStuff"/>

<html:select property="country"
onchange="this.form.methodToCall.value='setUp'; this.form.submit()">
   <html:options collection="dd1" property="value" labelProperty="label"/>
</html:select>

<html:select property="city">
  <c:if test="${!empty dd2}">
    <html:options collection="dd2" property="value" labelProperty="label"/>
  </c:if>
</html:select>

</html:form>

Hope that helped.

Cheers,
Daniel Silva.





On 11/2/05, Neil Meyer <neil.meyer@cxchange.co.za> wrote:
> I want to populate the first dropdown with every country in the world and
> then the second one will show the cities for this.
>
> The data is static but the result is big.
>
> Thanks
> Neil
>
> -----Original Message-----
> From: Thor Kristensen [mailto:tk@northmann.com]
> Sent: 02 November 2005 03:40 PM
> To: 'Struts Users Mailing List'
> Subject: RE: Struts dropdown boxes
>
> Or, if the data is pretty static and of a modest size, perform the
> population of the second drop down box in javascript.
> Although, it'd be much better as Thai proposed, since with javascript you'd
> write browser dependent code.
>
>
> Mvh
>   Thor
>
>
> > -----Original Message-----
> > From: Vu, Thai [mailto:Thai.Vu@parsons.com]
> > Sent: Wednesday, November 02, 2005 2:33 PM
> > To: Struts Users Mailing List
> > Subject: RE: Struts dropdown boxes
> >
> > I will submit that form whenever the first dropdown list
> > changes and then load the data to the 2nd.
> >
> > -----Original Message-----
> > From: Neil Meyer [mailto:neil.meyer@cxchange.co.za]
> > Sent: Wednesday, November 02, 2005 7:26 AM
> > To: Struts Users Mailing List
> > Subject: Struts dropdown boxes
> >
> > Hi,
> >
> > I need to have 2 dropdown boxes on my jsp page. The first
> > dropdowns selected value will determine what is pulled from
> > the database for the second dropdown.
> >
> > I know there is a few ways of doing it but would like to know
> > what most of the people recommend doing this.
> >
> > Your help is really appreciated.
> >
> > Regards
> > Neil Meyer
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Mime
View raw message