You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Gregg Bolinger <et...@embeddedthought.com> on 2004/06/01 20:31:16 UTC

Select Drop Down - Is this the easiest way?

In my application I will be displaying several drop down select lists 
that are populated from a database.  Nothing needs to happen when these 
items are selected.  When I submit the form I will get the values from 
the lists. 

I have provided the code below of how I am currently handling this.  My 
question is, since my lists are so simple, is this the easiest/simplest 
approach to simply create a drop down list with info from a database?  
Thanks for any tips/info.

Gregg Bolinger

I have a Department object (as an example)
package com.intrust.anykey.beans;

import java.io.Serializable;

public class Department implements Serializable
{
    private int id;
    private String name;
    private boolean selected;
   
    public Department(int id, String name)
    {
        this.id = id;
        this.name = name;
    }
   
    public int getId()
    {
        return this.id;
    }
   
    public String getName()
    {
        return this.name;
    }
   
    public void setSelected(boolean value)
    {
        this.selected = value;
    }
    public boolean getSelected()
    {
        return selected;
    }

}

These are the methods I have inside my NewIssue.java file

public Collection getDepartmentList()
    {
        if (departmentList == null)
        {
            //This will eventually be calls to the Database.
            departmentList = new ArrayList();
            departmentList.add(new Department(1, "PC Support"));
            departmentList.add(new Department(1, "Human Resources"));
           
        }
        return departmentList;
       
    }
   
    public Department getCurrentDepartment()
    {
        return currentDepartment;
    }
   
    public void setCurrentDepartment(Department value)
    {
        this.currentDepartment = value;
    }

And then in my NewIssue.html I have

<select jwcid="@Select" multiple="ognl:false">
      <span jwcid="@Foreach" source="ognl:departmentList" 
value="ognl:currentDepartment">
              <option jwcid="@Option" 
selected="ognl:currentDepartment.selected" 
label="ognl:currentDepartment.name"/>
      </span>
</select>



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


Re: Select Drop Down - Is this the easiest way?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
A few quick pointers for improvement:

- Use @PropertySelection

- Create an IPropertySelection model (there are a few implementations 
built-in, but we build our own custom ones that can take an Object[] 
and label/value property names and looks them up using PropertyUtils).

- Consider caching this type of lookup model in Global (use 
model="ognl:global.<some name>")

	Erik


On Jun 1, 2004, at 2:31 PM, Gregg Bolinger wrote:

> In my application I will be displaying several drop down select lists 
> that are populated from a database.  Nothing needs to happen when 
> these items are selected.  When I submit the form I will get the 
> values from the lists.
> I have provided the code below of how I am currently handling this.  
> My question is, since my lists are so simple, is this the 
> easiest/simplest approach to simply create a drop down list with info 
> from a database?  Thanks for any tips/info.
>
> Gregg Bolinger
>
> I have a Department object (as an example)
> package com.intrust.anykey.beans;
>
> import java.io.Serializable;
>
> public class Department implements Serializable
> {
>    private int id;
>    private String name;
>    private boolean selected;
>      public Department(int id, String name)
>    {
>        this.id = id;
>        this.name = name;
>    }
>      public int getId()
>    {
>        return this.id;
>    }
>      public String getName()
>    {
>        return this.name;
>    }
>      public void setSelected(boolean value)
>    {
>        this.selected = value;
>    }
>    public boolean getSelected()
>    {
>        return selected;
>    }
>
> }
>
> These are the methods I have inside my NewIssue.java file
>
> public Collection getDepartmentList()
>    {
>        if (departmentList == null)
>        {
>            //This will eventually be calls to the Database.
>            departmentList = new ArrayList();
>            departmentList.add(new Department(1, "PC Support"));
>            departmentList.add(new Department(1, "Human Resources"));
>                  }
>        return departmentList;
>          }
>      public Department getCurrentDepartment()
>    {
>        return currentDepartment;
>    }
>      public void setCurrentDepartment(Department value)
>    {
>        this.currentDepartment = value;
>    }
>
> And then in my NewIssue.html I have
>
> <select jwcid="@Select" multiple="ognl:false">
>      <span jwcid="@Foreach" source="ognl:departmentList" 
> value="ognl:currentDepartment">
>              <option jwcid="@Option" 
> selected="ognl:currentDepartment.selected" 
> label="ognl:currentDepartment.name"/>
>      </span>
> </select>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


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