Milan Milanovic
Mon, 12 May 2008 09:28:34 -0700
Hi,
>It can be List<Fruit>. Use the listKey/listValue attributes of s:select
>to control which properties of Fruit are used in populating the select
>options.
O.K. Thanks. One more question, is there possibility to show in a combo box
two values, for example I want to show id and name of the every fruit: 1 Apple ?
>That's a long way of saying that you can avoid calling the service every
>time, but it's entirely up to you how. My recommendation would be, don't
>worry about it; just call the service as needed. If it becomes a
>performance issue later on, address it then. Don't optimize until you
>have a demonstrable, quantifiable need to do so.
I want to optimize because my action could become slow. My page should have
5 combo boxes, 2 datetime pickers, and a 4-5 text boxes. This page will show
about 100 records in a table (with 5 columns), too. Actually I just need to fill
my combo boxes by using services in the first place, and then user can choose
that and go to enter other info into form which will become part of the above
mentioned table
(classic master/detail page). So, I can put that data into session and then to
check if
I have that data in session and if yes, to fill it, othervise I need to call
my service to get
data ?
If I remember corectly Struts 2 action class instance is created every time
action method is called ?
How can I use static fields ?
--
Thx in advance, Milan Milanovic
----- Original Message ----
From: Laurie Harper <[EMAIL PROTECTED]>
To: user@struts.apache.org
Sent: Monday, May 12, 2008 6:10:55 PM
Subject: Re: [Struts 2] Combo box question
Milan Milanovic wrote:
> Hi,
> I have a simple action class, for example like this:
> public class comboboxTag extends ActionSupport{
>
> private List<Fruit> fruits;
> private FruitService service;
> public String execute()throws Exception{
> fruits = service.getFruits();
> return SUCCESS;
>
> }
> }
> fruits field should be connected to combobox in my jsp page. I have two
> questions, the first is list
> for combobox should be only List<String> type or it can be List<Fruit> ?
It can be List<Fruit>. Use the listKey/listValue attributes of s:select
to control which properties of Fruit are used in populating the select
options.
> The second question is that I don't want every time to call my service to
> repopulate fruits field (and combo box),
> when one work in this page, I want to do this just once (in first start of
> the page) ? I ask this because I will have
> 5 combo boxes on a master/detail jsp page.
You can achieve that in any number of ways, but essentially you'll need
to 'remember' the answer from your service method, i.e. you need to
cache that data somewhere. Whether you choose to do that in static
fields in the action class itself, by putting the data into session or
application scope, or by handling the caching in the service or database
layer will depend on your particular requirements. Your strategy will
depend on how often the data changes (if ever), how critical it is for
your select lists to be up-to-date when the underlying data set has
changed, how the data is updated, etc.
That's a long way of saying that you can avoid calling the service every
time, but it's entirely up to you how. My recommendation would be, don't
worry about it; just call the service as needed. If it becomes a
performance issue later on, address it then. Don't optimize until you
have a demonstrable, quantifiable need to do so.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ