You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nandini Agarwal <na...@MRSTOCK.com> on 2001/08/29 19:23:03 UTC

RE: tags

Thanks so much. This makes thing so much clearer for me.
 

-----Original Message-----
From: chiji nwankwo [mailto:cn081@hotmail.com]
Sent: Wednesday, August 29, 2001 2:47 AM
To: struts-user@jakarta.apache.org
Subject: Re: <html:select> <html:options> tags


Hi,
Depending on what you are trying to do or the scale of the application
you are building, you can declare the collection within your jsp page
and put it within the pageContext or you can declare it in your Action 
subclass and put it in the session.  I found the last option to be a 
neater and better way of doing things.  I think it will be a good idea to
declare / define the collection in the Action subclass, incase you need
to populate the list from an external source, such as a database.
 
Example 1 (within jsp page, taken from struts example application -
subscription.jsp)
<%
  java.util.ArrayList list = new java.util.ArrayList();
  list.add(new org.apache.struts.webapp.example.LabelValueBean("IMAP
Protocol", "imap"));
  list.add(new org.apache.struts.webapp.example.LabelValueBean("POP3
Protocol", "pop3"));
  pageContext.setAttribute("serverTypes", list);
%>
........ other code ......
 <html:select property="type">
        <html:options collection="serverTypes" property="value"
                   labelProperty="label"/>
 </html:select>


........ other code ......
* The LabelValueBean is a utility class, which is part of the struts
example,
that creates a bean object.  The object contains label value pairs, as the
name implies.
 
Example 2 ( within Action subclass )
perform method - declared locally (avoid the use of instance 
variables in Action class).
ArrayList list = new ArrayList();   
...... other code .......
serverTypes.add( new LabelValueBean( <label - string>, <value - string> ) );
session.setAttribute( "serverTypes", serverTypes ); 


...... other code .......
 
jsp page.
 
<html:select property="type">
        <html:options collection="serverTypes" property="value" />
</html:select>
* labelProperty can be omitted if the label and value have the same value.
 
I hope this helps you.
Chiji
 


 
>From: Nandini Agarwal 
>Reply-To: struts-user@jakarta.apache.org 
>To: "'struts-user@jakarta.apache.org'" 
>Subject: <?xml:namespace prefix = html />tags 
>Date: Tue, 28 Aug 2001 15:02:49 -0700 
>MIME-Version: 1.0 
>Received: from [64.125.133.20] by hotmail.com (3.2) with ESMTP id
MHotMailBD55672B0073400438B1407D85140C9A0; Tue, 28 Aug 2001 15:33:15 -0700 
>Received: (qmail 3917 invoked by uid 500); 28 Aug 2001 22:05:39 -0000 
>Received: (qmail 3908 invoked from network); 28 Aug 2001 22:05:38 -0000 
>Received: from freedom.mrstock.com (216.52.133.36) by daedalus.apache.org
with SMTP; 28 Aug 2001 22:05:38 -0000 
>Received: from office-mail.mrstock.com (office-mail.mrstock.com
[63.204.129.19])by freedom.mrstock.com (Postfix) with ESMTP id 57E021B8for ;
Tue, 28 Aug 2001 17:03:22 -0400 (EDT) 
>Received: by office-mail.mrstock.com with Internet Mail Service
(5.5.2653.19)id ; Tue, 28 Aug 2001 15:02:54 -0700 
>>From struts-user-return-16231-cn081 Tue, 28 Aug 2001 15:34:00 -0700 
>Mailing-List: contact struts-user-help@jakarta.apache.org; run by ezmlm 
>Precedence: bulk 
>list-help: <?xml:namespace prefix = mailto /> 
>list-unsubscribe: 
>list-post: 
>Delivered-To: mailing list struts-user@jakarta.apache.org 
>Message-ID: 
>X-Mailer: Internet Mail Service (5.5.2653.19) 
>X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 
> 
>Hi, 
>I am new to java, struts, jsp and EJB. And guess what, I need help. 
> 
>What, I need to do is substitute the following with the >collection ...>
tag. 
> 
>
>  Less than $5,000 
>  Greater than $5,000 
>  Greater than $10,000 
>  Greater than $15,000 
>  Greater than $20,000 
>  Greater than $25,000 
>  Greater than $30,000 
>  Greater than $40,000 
>  Greater than $50,000 
>  Greater than $75,000 
>  Greater than $100,000 
>  Greater than $150,000 
>  Greater than $200,000 
>  Greater than $300,000 
>  Greater than $500,000 
>  Greater than $750,000 
>  Greater than $1,000,000 
> 
> 
> 
> 
> 
>I need help here with some code examples. Also, where do I need to create 
>the collection (In actionform ?)? 
> 
> 
>Thanks, 
>Nandini 

  _____  

Get your FREE download of MSN Explorer at http://explorer.msn.com
<http://go.msn.com/bql/hmtag_itl_EN.asp>