• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Single class for collection/select lists

 
andrew bills
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm new to struts and want to know if it's possible like webwork to store all my html select lists (collections) in a single class to have them loaded at startup (which I also don't know how to do)

In workwebwork I can do this
public class DataList extends ActionSupport
{
static List states = new ArrayList();
static List hospitalTypes = new ArrayList();
static List extrasTypes = new ArrayList();

}

ActionSupport is webwork specific, does Struts have something like this?

I know the method of putting the collection object in the session or request in the Action but I think that's just unnecessary coding and memory use.

Using the struts select tag for a collection is it possible to access the static lists that I have defined in a class?

<html:select name="employeeForm" property="department">
<html ptions collection="departments" property="id" labelProperty="description"/>
</html:select>

I don't want to have to create bean classes for every single select list in my website, and I don't want to have to put the lists in session/request in every Action. I know there must be way. Thanks!
 
John Smith
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know that method doesn't work with a list as struts needs to know the type of bean in the list in order to find the getter methods. If you change your data to being stored in arrays then you just do a bean efine before your select box on the array ensuring you set the type attribute of the tag to be your array type eg. com.myCompany.myBean [], the id of this define tag goes into your collection field and you can now access the properties.
[ December 07, 2004: Message edited by: John Smith ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic