struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "MADISHETTY, ASHOK [AG-Contractor/8042]" <ashok.madishe...@monsanto.com>
Subject RE: How to set the property of a drop-down select list from an action class?
Date Mon, 04 Sep 2006 09:46:42 GMT
Hi,

 

You may try following:

 

Enumeration expenseTypeList = expenseTypes.elements();  // Vector of 

                                                ExpenseType class objects

 

ExpenseType type = null;

 

<select name='select'>

 

if (expenseTypeList != null) {

  while(expenseTypeList.hasMoreElements()) {

   type = (ExpenseType) expenseTypeList.nextElement();

 <option value='"+type.getTypeCode()+"'>+type.getTypeDescription()+</option>

 

 } 

} 

</select>

 

This will display type description in list box and retrieve typeCode when
you call select.value();

 

Is that what you wanted?

 

Thanks

Ashok

 

 

 

 

-----Original Message-----
From: Tom Bednarz [mailto:list@bednarz.ch] 
Sent: Monday, September 04, 2006 2:24 PM
To: Struts Users Mailing List
Subject: How to set the property of a drop-down select list from an action
class?

 

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

 


---------------------------------------------------------------------------------------------------------
This e-mail message may contain privileged and/or confidential information, and is intended
to be received only by persons entitled to receive such information. If you have received
this e-mail in error, please notify the sender immediately. Please delete it and all attachments
from any servers, hard drives or any other media. Other use of this e-mail by you is strictly
prohibited.


All e-mails and attachments sent and received are subject to monitoring, reading and archival
by Monsanto. The recipient of this e-mail is solely responsible for checking for the presence
of "Viruses" or other "Malware". Monsanto accepts no liability for any damage caused by any
such code transmitted by or accompanying this e-mail or any attachment.
---------------------------------------------------------------------------------------------------------


Mime
  • Unnamed multipart/alternative (inline, 7-Bit, 0 bytes)
View raw message