You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Caroline Jen <ji...@yahoo.com> on 2003/11/30 06:48:04 UTC

How Do I Create This Drop-Down List in Struts?

My ArrayList is a collection of bean object.  The
ArrayList is created this way:

public Collection findEditors( String userrole, String
category ) 
{
   ..........
   EditorBean editorBean = null;
   ArrayList editors = new ArrayList();
   // database access code
   while( rs.next() )
   {
      editorBean = new EditorBean(
rs.getString("user_name") );
      editors.add( editorBean );
   }
   return editors;
   .......
}

and my EditorBean is like:

public class EditorBean 
{
   private String name;

   public EditorBean() {}

   public EditorBean( String name )
   {
      this.name = name;
   }
   public String getName() {
      return Name;
   }
   public void setName( String name ) {
      this.name = name;
   }
}

After "editors" is returned, I create a session
object:

session.setAttribute( "EDITORS", editors );

How do I create a drop-down list for this collection
of editors?

<html:select size="1" property="??????"
multiple="false">
    <html:options collection="??????" property="name"
labelProperty="name"/>
</html:select>



__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How Do I Create This Drop-Down List in Struts?

Posted by Mark Lowe <ma...@talk21.com>.
The collection that you want to iterate through and the form property 
aren't linked as such only when you nest the html:options tag in the 
html:select tag

So your html:select form property is like any other form property, and 
when submitted will only the form property will be set to only one 
value from the list.
<html:select property="editor">
	//now the list in the options tags is only really associated
	//with the form property as its nested in the html:select
	<html:options collection="mycollection"

the property attribute in the html:options tag is to drill to the 
property of the bean thats exposed during the iteration and hasn't much 
to do with the form itself.
..

Cheers Mark


On 30 Nov 2003, at 05:48, Caroline Jen wrote:

> My ArrayList is a collection of bean object.  The
> ArrayList is created this way:
>
> public Collection findEditors( String userrole, String
> category )
> {
>    ..........
>    EditorBean editorBean = null;
>    ArrayList editors = new ArrayList();
>    // database access code
>    while( rs.next() )
>    {
>       editorBean = new EditorBean(
> rs.getString("user_name") );
>       editors.add( editorBean );
>    }
>    return editors;
>    .......
> }
>
> and my EditorBean is like:
>
> public class EditorBean
> {
>    private String name;
>
>    public EditorBean() {}
>
>    public EditorBean( String name )
>    {
>       this.name = name;
>    }
>    public String getName() {
>       return Name;
>    }
>    public void setName( String name ) {
>       this.name = name;
>    }
> }
>
> After "editors" is returned, I create a session
> object:
>
> session.setAttribute( "EDITORS", editors );
>
> How do I create a drop-down list for this collection
> of editors?
>
> <html:select size="1" property="??????"
> multiple="false">
>     <html:options collection="??????" property="name"
> labelProperty="name"/>
> </html:select>
>
>
>
> __________________________________
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now
> http://companion.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: How Do I Create This Drop-Down List in Struts?

Posted by Mohan Radhakrishnan <mr...@cellexchange.com>.
You should have a property in your form bean where the user selection will
go. In this case the property is "name"

<html:select size="1" property="Property in the form bean to hold the
selection"
multiple="false">
    <html:options collection="EDITORS" property="name"
labelProperty="name"/>
</html:select>

Mohan

-----Original Message-----
From: Caroline Jen [mailto:jiapei_jen@yahoo.com]
Sent: Sunday, November 30, 2003 11:18 AM
To: struts-user@jakarta.apache.org
Subject: How Do I Create This Drop-Down List in Struts?


My ArrayList is a collection of bean object.  The
ArrayList is created this way:

public Collection findEditors( String userrole, String
category )
{
   ..........
   EditorBean editorBean = null;
   ArrayList editors = new ArrayList();
   // database access code
   while( rs.next() )
   {
      editorBean = new EditorBean(
rs.getString("user_name") );
      editors.add( editorBean );
   }
   return editors;
   .......
}

and my EditorBean is like:

public class EditorBean
{
   private String name;

   public EditorBean() {}

   public EditorBean( String name )
   {
      this.name = name;
   }
   public String getName() {
      return Name;
   }
   public void setName( String name ) {
      this.name = name;
   }
}

After "editors" is returned, I create a session
object:

session.setAttribute( "EDITORS", editors );

How do I create a drop-down list for this collection
of editors?

<html:select size="1" property="??????"
multiple="false">
    <html:options collection="??????" property="name"
labelProperty="name"/>
</html:select>



__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org