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]