struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Bednarz <l...@bednarz.ch>
Subject How to set the property of a drop-down select list from an action class?
Date Mon, 04 Sep 2006 08:53:30 GMT
I like to display a dop-down select list and select an apropriate entry 
from that list in an action:

This fills the list box:

<html:select property="expenseType">
   <html:options collection="expenseTypes" property="typeCode"
      labelProperty="typeDescription"/>


The expenseTypes is a Vector of the following class:


public class ExpenseType
{
   long typeCode;
   String typeDescription;
		
   public ExpenseType()
   {
   }
		
   public ExpenseType(long typeCode, String typeDescription)
   {
     super();

     this.typeCode = typeCode;
     this.typeDescription = typeDescription;
   }

   ... setters and getters
}


In my Action class I usually use the following code to populate the form 
with values from a business object:

PropertyUtils.setSimpleProperty(form, "expenseName", expense.getName());
...

How do I pre-select the correct entry in my drop-down list-box? In my 
business object I have a value that matches the typeCode of the above 
class but dispayed should be the typeDescription.

The collection is a vector, but I do not know the postition of the item 
to select, I only have its value. So I cannot use 
ProperyUtils.getIndexedProperty(..). But I can also not use 
getMappedProperty() since a vector has no keys....

So how is this done with Vectors? Or should in general Hashtables be 
taken for drop-down listboxes?

Tom

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


Mime
View raw message