Reputation: 93
I have a query regarding select box in struts2.
Currently What I am doing is:
<s:select list="#session.ALLBranchList"
name="branchDetail.branchCode" id="selectedbranch" value="%{branchDetail.branchCode}"
headerKey="select"
headerValue="Select"
listKey="branchCode"
listValue="branchName"
></s:select>
The output for the above is all the branch name a populated in the drop down. and when I am submitting the form I am getting the key value as branch code. I am satisfied with this . BUT Now
What I want to achieve is that in the drop down Values should be populated in this format: 1-INDIA 2-USA 3-UK 4-KOREA
one way what I can think of is I form a list having the values in this way. But If I don't wish to alter my list or don't want to write java code to achieve it.Is this possible doing by making changes in select tag? Please suggest a way to achieve this or what am I thinking is hypothetical..
Upvotes: 2
Views: 2756
Reputation: 2313
Try this listValue="branchCode+'-'+branchName"
.
Your complete code:
<s:select list="#session.ALLBranchList"
name="branchDetail.branchCode"
id="selectedbranch"
value="%{branchDetail.branchCode}"
headerKey="select"
headerValue="Select"
listKey="branchCode"
listValue="branchCode+'-'+branchName" />
Upvotes: 1