Approaches for Prepopulating dropdowns in Jsp using struts.

Hi,

I'm having a functionality working of pre-populating dropdowns using struts like:

ArrayList list = getRoles(); //This method will return list of roles

request.setAttribute("roles", list);

By setting this collection in the request it will be availbel to <html:select and ><html:options> tags for pre-populating. My question here is do we need to set the list (that is to be displayed in the JSP) in request scope deliberately, or there are other better approaches as well to do the same, like using expression language and accessing the method directly.

Thanks,

Prashant.

[631 byte] By [prashantkaushikjava@sun.coma] at [2007-11-27 9:38:33]
# 1

Why dont you use ActionForm.

declare a private variable

//variable

private List roles=null;

//methods

public List getRoles();

public void setRoles(List roles);

and in ActionClass

ArrayList list = getRoles(); //This method will return list of roles

form.setRoles(list);

This collection object will be available in the jsp forwarded from that action in the scope specified in the struts-config.

then use

<html:select>

<html:options collection="roles" labelProperty="name"property="id" />

</html:select>

R@njita at 2007-7-12 23:12:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...