I am having a weird problem where my <s:select> tag render the value on HTML, but when I submit the form, the addFieldError() method fired. I don't understand why it's not passing any value but look into the HTML source I found
here is my <s:select>
I use struts2 action to populate employeeType
so can anyone tell me why I get <option value="">
and what I couldnt understand was that the <s:select> tag worked before, I haven't change anything from the code I pasted above.
Thanks for help
Yash Dutt
Greenhorn
Joined: Apr 01, 2009
Posts: 5
posted
0
try to use map instead of linked list......... i think it will work for you
Mr. Newton, I don't really understand what the documentation for the listValue attribute
last night I try removing listKey and it works but "Busser" automatically get selected
Can you elaborate a little more on examples of how to use listValue?
do you have to use listKey in conjunction with listValue?
Davie you need to understand why the code is behaving that way. You are using a List to show the <select> tag. The list contains strings. So when you specify "key" as listKey or listValue, then it tries to look for a property named "key" inside your elements of the List. And it finds nothing. If you used a Map to create the <select> tag, then it would have used the key of the map when you specify listKey = "key" (which is also the default behavior). I think giving nothing as listKey and listValue has solved your problem, and if you want a header key, then you can use headerKey and headerValues of the <select> tag to set the first option of the select box...
hi Davie try any one of the followings........
USAGE-1 <s:select headerKey="-1" headerValue=" Select Employee " list="#employeeTypes"/>
-----------------------------------------------------------------
public class Register extends ActionSupport {
private Hashtable employeeTypes;
public String execute() throws Exception{
EmployeeTypes = new Hashtable();
EmployeeTypes.put("1","Host");
EmployeeTypes.put("2","Server");
EmployeeTypes.put("3","Busser");
return SUCCESS;
}
public List getEmployeeTypes() {
return EmployeeTypes;
}
}
==============================================================================
USAGE-2 <s:select headerKey="-1" headerValue=" Select Employee " list="#employeeTypes" listValue="id" listKey="name"/>
------------------------------------------------------------------
public class Register extends ActionSupport {
private List<EmployeeType> employeeTypes;
public String execute() throws Exception{
EmployeeType = new LinkedList<EmployeeType>();
EmployeeType.add(new EmployeeType("1","Host"));
EmployeeType.add(new EmployeeType("2","Server"));
EmployeeType.add(new EmployeeType("3","Busser"));
return SUCCESS;
}
public List getEmployeeTypes() {
return employeeTypes;
}
}
public class EmployeeType{
private String id;
private String name;
public EmployeeType(String id,String name){
this.id=id;
this.name=name;
}
public void setId(String id){
this.id=id;
}
public String getId(){
return this.id;
}
public void setName(String id){
this.name=name;
}
public String getName(){
return this.name;
}
}
Davie Lin
Ranch Hand
Joined: Aug 05, 2007
Posts: 294
posted
0
Thank you Yash and Ankit, I am just confused because it worked before. But I need to understand the behavior of the code like what Ankit suggested. That usually takes some patients, I need to develop the patients to see the behavior of the code. From this I also finding out some of the design flaw I have, I know what to change now, thanks
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.