aspose file tools*
The moose likes Struts and the fly likes listbox problem - seems simple, but.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "listbox problem - seems simple, but.." Watch "listbox problem - seems simple, but.." New topic
Author

listbox problem - seems simple, but..

Raj Bhandari
Ranch Hand

Joined: Oct 19, 2005
Posts: 97
Hi,
I have a doubt with a listbox in struts.

I have populated my listbox from the database.. now I want to highlight the items which were selected by the user in the past (from some other table)..

If I were to just display the selected items, I would do this:

<c:forEach var="tailno" items="${result.tailno}" varStatus="indexCount">
<c: out value="${tailno}"/><br/>
</c:forEach>

This is what I'm doing to populate my listbox right now (but how to highlight ?):

<html:select property="tailno" value="0" multiple="true" size="5">
<html: optionsCollection name="formbean" property="tailnoList" label="label" value="value" />
</html:select>

I would have used the value propery in html:select if there was only one value but what should I do now knowing that ${result.tailno} is an array containing multiple values selected by the user ?

Thanks!
[ July 19, 2006: Message edited by: Raj Bhandari ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The <html:select> tag automatically looks at the existing value of the ActionForm property specified in the property attribute (tailno in your case) and highlights the values that match the values in the property. You're messing this up, though, by specifying value="0". Just remove the value attribute entirely and it should work.

Also, make sure there is a tailno property of type String[] in your ActionForm bean and that it's been populated prior to displaying the JSP.


Merrill
Consultant, Sima Solutions
Raj Bhandari
Ranch Hand

Joined: Oct 19, 2005
Posts: 97
Hi Merrill,

Thanks for the reply as always.
I tried what you suggested but it still doesn't highlight the selected values.
I have checked that the values are there in tailno property.

Here is what I'm doing:



Here is my struts-config.xml:

<form-property name="tailno" type="java.lang.String[]"/>
form-property name="tailnoList" type="java.util.ArrayList"/>

Any suggestions ?
Thanks!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Are you 100% sure that each item in the tailno array matches the value property of one of the beans in your tailnoList ArrayList?
Raj Bhandari
Ranch Hand

Joined: Oct 19, 2005
Posts: 97
Hi Merrill,

You were 100% right.
While driving yesterday, I realized I was matching the tailno with the label and not the value. Once, I fixed that now.. its working fine.
Thanks a lot!
 
Consider Paul's rocket mass heater.
 
subject: listbox problem - seems simple, but..