Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html:options default item selection

 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have a html ptions which is using catValues collection. This collection is loaded with all the categories. The following is the code
<html:select property="contextCode"> <html ptions collection="catValues" property="categoryCode" labelProperty="categoryName" />
</html:select>
i wanted to set the index of the select box to the second element is there a way to do it in the html options box
Thanks
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are a couple of ways you can do this...

1. break the <htmlptions> into iterations of <htmlption>. track the indexId (with logic:equal or c:if) and generate the <htmlption> with selected="true" attribute

2. if your collection is generated from the action, do form.set("contextCode", secondOptionValue); inside the action before forwarding it to the page.
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
but the problem is that the page is first time initialized. so i have the collection in the session variable and it is used to populate the html ptions tag. So the page is loaded for the first time and it does not go to the action class. i think the first method is fine. Could you please eloborate how i expand the html ptions tag.
Thanks
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is the second value in the dropdown always a known value? if so, you can initialize your form-property (using the initial="xxx" attribute) to that value. if you can't do this, i'll explain the <html ption>.
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Alan
its works now. i just set the initial property in my dynaaction form declaration in the struts-config.xml file
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic