This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Combobox in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Combobox in Struts " Watch "Combobox in Struts " New topic

Combobox in Struts

Tharindu Priyath

Joined: Nov 01, 2012
Posts: 5
How to use Combo box in Struts 2?
I want to load Combo box from List Or Map .
I try to do it like this.

---------------------------------------jsp page-------------------------------------------------------

<% List<Country> countries = (List<Country>) request.getAttribute("countries"); %>
<s:set var="countryList"><%=countries%></s:set>
<s:select name="country" list="%{countryList}" label="Select a country" />


[Sri Lanka,India,USA]

But elements in 'countries' list object are not added to the combo box. 'toString' representation of List object is displayed in combo box.
How to add countries as element of the Combo box.

[Thumbnail for Picture1.png]

Joe Ess

Joined: Oct 29, 2001
Posts: 8836

Tharindu Priyath wrote:


Why would you do such a thing? It looks like you are trying to use Struts 1 ideas, setting a request parameter and using scriptlets. Struts 2 greatly simplifies things. You can use an OGNL literal list:

If you have a method in your action getCountryList that returns a List or Map (if it returns a map, the map key becomes the option value parameter and the map value is what is displayed to the user) you can access it without all the hoops you were jumping through:

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
subject: Combobox in Struts
Similar Threads
Sturts Urgent query
DisplayTag - Want to generate Dynamically record Per Page
Dependent Drop-down Combo boxes
selectOneListbox value from an ArrayList
problem to populate select tag value from database using struts2