Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

listbox problem - seems simple, but..

 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic