struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Pilgrim" <peter.pilg...@db.com>
Subject Re: iterate tag question
Date Mon, 12 Nov 2001 10:24:44 GMT


This is wrong. You are only assignment ArrayList element thats refer to
the same object instance `strMenu'.

What you need to do is
            ArrayList alMenu = new ArrayList();
            String strMenu[] = new String[2];
            strMenu[0] = "Tenant Information";
            strMenu[1] = "/TenantInfo";
            alMenu.add(strMenu);
            strMenu[] = new String[2];
            strMenu[0] = "Tenant Information";
            strMenu[1] = "/TenantInfo";
            alMenu.add(strMenu);

But this is clumsy. Borrow the `LabelValueBean' from Struts
Example or write an association class for you own project
Then you can write __better__ Java code.

          ArrayList alMenu = new ArrayList(
          LabelValue labVal = new LabelValue(
               "Tenant Information",
               "/TenantInfo" );
            alMenu.add( labVal );

Or even more elegantly:

          ArrayList alMenu = new ArrayList(
          alMenu.add( new LabelValue(
               "Tenant Information",
               "/TenantInfo" ) );
          alMenu.add( new LabelValue(
               "Service charge data",
               "/Charges" ) );

Benefit of this you put the collection is "request" or "session" scope.

          request.setAttribute( "MY_COLLECTION_LIST", almenu );

You grab it with the html:options custom action like this
( assume the LabelValueBean has two method called "getOptionName" and
"getOptionValue" )

          <bean:define id="privateDancer" name="MY_COLLECTION_LIST" />
          <html:options collection="privateDancer"
               property="optionValue"
               labelProperty="optionName" />

Eh voila!
--
Peter Pilgrim                 ++44 (0)207-545-9923
                                                      //_\\
"Mathematics is essentially the study of islands of  =======
disparate subjects in a sea of ignorance."           || ! ||
Andrew Wiles _____________


---------------------------------------- Message History ----------------------------------------


From: Frédéric Houbie - ABSIS-GROUP <fhoubie@absis-group.be> on 08/11/2001 17:41 CET
--<CUT>--

Hi,

I need to use an arraylist in a iterate tag, i fill the arraylist with
String arrays like that :

            ArrayList alMenu = new ArrayList();
            String strMenu[] = new String[2];
            strMenu[0] = "Tenant Information";
            strMenu[1] = "/TenantInfo";
            alMenu.add(strMenu);
            strMenu[0] = "Tenancy Schedule";
            strMenu[1] = "/TenantSched";
            alMenu.add(strMenu);
            strMenu[0] = "Service charge data";
            strMenu[1] = "/Charges";
            alMenu.add(strMenu);
            strMenu[0] = "Stacking Plan";
            strMenu[1] = "/StackingPlan";
            alMenu.add(strMenu);
            strMenu[0] = "Tenants rental balance";
            strMenu[1] = "/TenantRental";
            alMenu.add(strMenu);
            strMenu[0] = "Break dates calendar";
            strMenu[1] = "/BreakDates";
            alMenu.add(strMenu);
            session.setAttribute("Menu", alMenu);


how can I access the item of String array in jsp <bean> tag. Do I have to
write a class with getter and setter instead ?

--<CUT>--


--

This e-mail may contain confidential and/or privileged information. If you are not the intended
recipient (or have received this e-mail in error) please notify the sender immediately and
destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material
in this e-mail is strictly forbidden.



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


Mime
View raw message