• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

access variable of a s:select (struts2)

 
Greenhorn
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>
</select>

PERFECT!

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.
listValue="%{filter()}"

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>
</select>

Hope this will help you in addition to what you tried before.
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!