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

html:options values getting appended

 
Sivaraman Lakshmanan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I just wrote a very simple struts example where I am populating a combo box with some values. I use <html ptions> for populating this. First I populate just 4 values, the page loads fine but when i refresh the page I see 8 values (ie the 4 values added twice) in the html combo box.
I have reset the session values etc still I am facing the same problem.
Some struts expert please help...
I am posting my code below...



Thanks in Advance
 
Soumya Saha
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sivaraman,
Try this out ..in JSP.

<bean efine id="lstplace" name="WelcomeForm" property="place"/>
<html:select property="selectedPlace">
<html ptions collection="lstplace" property="key" labelProperty="value"/>
</html:select>

Thanks
 
Sivaraman Lakshmanan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply. I put the code that u gave in my JSP but its throwing a error when I run the page. The error is

javax.servlet.ServletException: No getter method available for property key for bean under name lstplace

help me to get rid of this error
 
Soumya Saha
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sivaraman,
Sorry for that..
u can do it either way..

1.Have a bean class ..like struts label value bean..with 2 attributes(Key and Value)...set ur dropdown values in the key and value attributes of the Bean and then add the bean in the arraylist.(u should have a new instance of the Bean every time while adding to the arrayList..hope u got my point..).Then that code should work..

2.Or else ..U can use a HashMap(lstPlace) and set the values like...HmMap.put("Chennai", "Chennai");..and set it in the Request Scope and acces it from the JSP ..Then u don't need to define any bean id..

Please get back incase of errors...

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic