You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by hans albers <su...@hotmail.com> on 2002/06/03 08:56:03 UTC

Where to put the code for filling an ArrayList

Hi there

I want a dropdown-box filled by a bean.

I fill the Arrraylist inside the jsp as you can see, but I don't
want to have this code in the jsp because the data later comes
from a database.
Where and how do I have to write this code (a...b) for the list be
accessed by the show.jsp?
In the showForm.java or showAction.java or in the Action.java of the
page before the show.jsp?

In my show.jsp:
<% //a
  java.util.ArrayList list = new java.util.ArrayList();
  list.add(new LabelValueBean("Art1", "a1"));
  list.add(new LabelValueBean("Art2", "a2"));
  list.add(new LabelValueBean("Art3", "a3"));
  session.setAttribute("my_list",list);
  // b
%>

--------
  <html:select property="value">
        <html:options collection="list" property="value"
          labelProperty="label"/>
  </html:select>

_________________________________________________________________
Testen Sie MSN Messenger für Ihren Online-Chat mit Freunden: 
http://messenger.msn.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Where to put the code for filling an ArrayList

Posted by Anders Rosén <an...@rosentech.com>.
As a custom tag? I do this in one of my applications, when populating
selects from a table in a database.

<%@ taglib uri="/WEB-INF/myTagLib.tld" prefix="custom" %>

<custom:myTag name="list"/>

<html:select property="aProperty">
   <html:options collection="list" property="value"
                 labelProperty="label"/>
</html:select>

You need to create the java class (subclassing TagSupport) implementing
the doStartTag() and optionally doEndTag() methods. Create the ArrayList
object and put it somewhere convinient, for example as an attribute in
the request object. You also need to define the new tag in a tld-file.

Regards,
/Anders

-----Ursprungligt meddelande-----
Från: hans albers [mailto:super4711@hotmail.com] 
Skickat: den 3 juni 2002 08:56
Till: struts-user@jakarta.apache.org
Ämne: Where to put the code for filling an ArrayList


Hi there

I want a dropdown-box filled by a bean.

I fill the Arrraylist inside the jsp as you can see, but I don't want to
have this code in the jsp because the data later comes from a database.
Where and how do I have to write this code (a...b) for the list be
accessed by the show.jsp? In the showForm.java or showAction.java or in
the Action.java of the page before the show.jsp?

In my show.jsp:
<% //a
  java.util.ArrayList list = new java.util.ArrayList();
  list.add(new LabelValueBean("Art1", "a1"));
  list.add(new LabelValueBean("Art2", "a2"));
  list.add(new LabelValueBean("Art3", "a3"));
  session.setAttribute("my_list",list);
  // b
%>

--------
  <html:select property="value">
        <html:options collection="list" property="value"
          labelProperty="label"/>
  </html:select>

_________________________________________________________________
Testen Sie MSN Messenger für Ihren Online-Chat mit Freunden: 
http://messenger.msn.com


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>