• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Combobox in Struts

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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" />

---------------------------------------output-----------------------------------------------------------

[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.
Picture1.png
[Thumbnail for Picture1.png]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:


 
For my next trick, I'll need the help of a tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic