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 17:24:54 GMT
Hi Martin,

Hmm, thanks for the link.

Finally my problem is, that in the generated HTML page NONE of the 
option tags has the attribute SELECTED. So my drop-down list box 
displays the whole collection as expected, but setPropertyUtils seems to 
have no impact otherwise the correct value should be selected.

So probably could someone post the code for a simple problem:

I have a select box eg

0 Value0
1 Value1
2 Value2

Displayed to the user is
Value0
Value1
Value2

If a specific record is looked at, the Value might be 1, so I should set 
the property to 1 and the list-box should show
Value1 to the user as selected item.

This should be a very common problem but I simply cant get it working!!!

Tom

Martin Gainty wrote:
> Good Morning Tom
>
> If I understand your question you want to set properties via PropertyUtils.setPropertyUtils(InstantiatedBeanObject,BeanAttributeToSet,value)?
> An excellent tutorial showing how to construct the Bean as well as setPropertyUtils methods
is located here
> http://brahe.discursive.com/viewcvs/commons-beanutils5/trunk/src/java/org/apache/commons/beanutils/package.html?rev=1
>
> HTH
> Martin --
> *********************************************************************
> This email message and any files transmitted with it contain confidential
> information intended only for the person(s) to whom this email message is
> addressed.  If you have received this email message in error, please notify
> the sender immediately by telephone or email and destroy the original
> message without making a copy.  Thank you.
>
>
>
> ----- Original Message ----- 
> From: "Tom Bednarz" <list@bednarz.ch>
> To: "Struts Users Mailing List" <user@struts.apache.org>
> Sent: Monday, September 04, 2006 7:13 AM
> Subject: Re: How to set the property of a drop-down select list from an action class?
>
>
>   
>> 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
>>
>>     
> >


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


Mime
View raw message