Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<s:select how to fill with key and value

 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
First i am thanking you all who helped me to solve the problme.

Now i need to fill a select combo <s:select with key and value attribute. I am able to fill it with only values but no key. How can i set key value for each option content in ><s:select>



This is my select combo and i am listing the method that i used to fill the combo

private List day;
List qstCategory;
List qstCategoryKey;
String usrQst;






Waiting for a replay .


Regards,
Biny Balan
binypanackal@gmail.com
 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
expecting replay
can i fill a <s:select using hashtable>
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if you use a java.util.List in the list attribute of the select tag, then the listKey and listValue both point to the values in the list. If the elements in the list are complex objects like for example a User class object with properties name and id, then you can set the listKey and listValue attributes to point to then like for example - listKey="id" listValue="name".

If you don't want that, then you must use a java.util.Map so that the listKey points to the keys in the map and listValue points to the values in the map...
 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if i created a class

Sucategory{
String id
String value
}

and i add object of the same to the list

and if i give like="list" listKey="id listValie="value" wether it will work

 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
biny panackal wrote:So if i created a class

Sucategory{
String id
String value
}

and i add object of the same to the list

and if i give like="list" listKey="id" listValie="value" whether it will work



I think it will work if you write listValue instead of listValie and the the list contains a list whose elements are of type Sucategory...
 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a class now with two field key and value





i filled to to list

List qstCategory


qstCategory = new ArrayList();
qstCategory.add(new AnsCategory("A","AAA"));
qstCategory.add(new AnsCategory("B","BBB"));
qstCategory.add(new AnsCategory("C","CCC"));

getter and setter method



public List getQstCategory(){
return qstCategory;
}



and for <s:select




I am not getting the proer value filled in the drop down
public void setQstCategory(List qstCategory){
this.qstCategory=qstCategory;
}




>
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding javabean methods into AnsCategory class



Also why are you using this syntax

listKey="#qstCategory['key']"

This means that you are trying to access an attribute from the ActionContext. The listKey and listValue are string properties. Use this

 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thaks a lot . That worked fine.

But i still have some doubt in that concept. When we create a object. The values are assigned to the appropriate variables. when i am creating other with other the list hold object of diffrent values in each position. So why we need to use the bean property getter and settter since it will also do the same one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic