This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes html:options values getting appended Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:options values getting appended" Watch "html:options values getting appended" New topic
Author

html:options values getting appended

Sivaraman Lakshmanan
Ranch Hand

Joined: Aug 02, 2003
Posts: 231
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


Regards,
Sivaraman.L
Soumya Saha
Ranch Hand

Joined: Apr 14, 2006
Posts: 64
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

Joined: Aug 02, 2003
Posts: 231
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

Joined: Apr 14, 2006
Posts: 64
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: html:options values getting appended