I think the question was (and my question is), can the collection used for the
options tag be a property of some bean, like the form bean? Or does the
collection itself have to be in the request (or some other) context, as you've
shown below.

----- Original Message -----
From: Ted Husted
To: Struts List
Sent: Tuesday, January 16, 2001 11:24 PM
Subject: Re: options-Tag


The simplest thing is to use the LabelValueBean class provided by the example.

In your Action, a database query (or equivalent) would create a collection of
LabelValueBeans, and then insert the collection into the request context.

First, the database query executes a query and returns the rowset as an instance
variable named list..

Then you can transfer the rowset to a collection (e.g. ArrayList)

  public ArrayList fetchList() throws SQLException {
    if (result==null) { return (null); }
    else {
      String defaultValue = "1980"; // FIXME - YEAR
      String defaultLabel = "ALL"; // FIXME
      ArrayList list = new ArrayList();
      list.add(new LabelValueBean(defaultLabel,defaultValue)); // Defaults at
top of the list
      while (result.next()) {
        String year = result.getString(1);
        list.add(new LabelValueBean(year, year));
      }
      return(list);
  }


And,

request.setAttribute("salesYears",salesYearsList);

There is a working example of this using a DISTINCT query in "Struts with a
Fruit Glaze", found at < http://husted.com/about/struts >

I haven't tried it, but I think the part about "only property" refers to whether
the label (in the drop down) use the same or different labels.

*********** REPLY SEPARATOR ***********

On 1/15/2001 at 11:28 PM Johann Dorn wrote:
Hello,

I have some problems with the options tag, which I want to use in conjunction
with my ActionForm.


In the example application the collection is filled directly in the
subscription.jsp
<%-- In real life, these would be loaded from a database --%>
<%
  java.util.ArrayList list = new java.util.ArrayList();
  list.add(new org.apache.struts.example.LabelValueBean("IMAP Protocol",
"imap"));
  list.add(new org.apache.struts.example.LabelValueBean("POP3 Protocol",
"pop3"));
  pageContext.setAttribute("serverTypes", list);
%>




According to the Documentation the options-Tag can be used in a different way:
- The ActionForm  bean can contain the collection,
- Only property is specified - The value of this attribute is the name of a
property of the ActionForm bean associated with our form, which will return the
collection.


But I alwas get expceptions like
'javax.servlet.ServletException: Cannot create iterator for PersForm@dafb2f4a'


Can anyone give me an example or some hints how the options-Tag must be used in
conjunction with the ActionForm?


Best Regards
Johann Dorn

Reply via email to