Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

access variable of a s:select (struts2)

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an array

{"item1", "item2"}

that I want to put it on a select

like that:

the result is:

<select id="editar_" name="">
<option value="item1">item1</option>
<option value="item2">item2</option>


now, I want the text to be different of the value.
and the text I'll have after a filter.

the idea is to do something like this:

the problem is, I dont known how to access the variable "item" that contains the value "item1" or "item2" to use it on a filter.

is it possible to access this information from a simple array ?
(I known that if I had a list of objects it is through the name of the field of the object like listValue="%{filter(description)}" if the object has a field called description)

but I need to access the array.

thanks in advance

Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this as follows :

<s:select list="testArray" listValue="filterArray(getTestArray()[index])" />

where your model should contain corresponding method for data acess:

public String[] getTestArray(){
//Add your array here I have used string for simplification you can use any object
return new String[]{"item1test","item2test"};

public String filterArray(String str){
//Do alll the customization for display here
return "added : "+str;
public int getIndex(){
//Return the index here, it's upto you how to return the selected index
//U can do it by setting into a hidden field on onChange event of the select
//and then access that property here.
// I have just hardcode here for demonstration
return 0;

You will get HTML as follows :

select name="" id="testSelect">
<option value="item1test">added : item1test</option>
<option value="item2test">added : item1test</option>

Hope this will help you in addition to what you tried before.
Popeye has his spinach. I have this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic