struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Bednarz <l...@bednarz.ch>
Subject Re: How to set the property of a drop-down select list from an action class?
Date Mon, 04 Sep 2006 11:13:41 GMT
Hi,

Thanks for your feedback but it is NOT what I want to do. This looks 
very much like mixing Java and HTML. I like to fill the form properties 
in my ActionClass and use JSP to display them.

So in my Action Class there should be something like

PropertyUtils.setSimpleProperty(form, "expenseType", <expense type that should match ONE
entry in my collection>);

In the JSP as shown in my original message:



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

where expenseTypes is the collection containing instances of expenseType 
class and typeCode is the value and typeDescription the label displayed 
in the drop-down listbox.

I currently don't know how to set the property using PropertyUtils in my 
Action class.

Tom

MADISHETTY, ASHOK [AG-Contractor/8042] wrote:
> 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.
> ---------------------------------------------------------------------------------------------------------
>
>
>   


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


Mime
View raw message