This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes I wanted to populate in struts 2" title="" /> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "I wanted to populate "id" as value and "employeeName" as a name  <s:select> in struts 2" Watch "I wanted to populate "id" as value and "employeeName" as a name  <s:select> in struts 2" New topic
Author

I wanted to populate "id" as value and "employeeName" as a name <s:select> in struts 2

Arun R Upadhya
Greenhorn

Joined: Apr 01, 2011
Posts: 1
<h1>**In my project i am using Struts2, Spring2.5 and JPA(Hibernate)**<h2>

my "**EmployaaDaoJpa**"


Query query = entitymanager.createQuery("SELECT e.employeeName FROM Employee e");
List<String> lstEmployee = query.getResultList();

- using this i am getting all the employee names. and in my action class i will get all the states, both are declared in my VO (I implemented ModelDriven)

List<String> lstEmployees;
String yourEmployee;

in the action class i will initialize the lstStates like

lstEmployees = employeeDao.getAllEmployees();

and in my jsp

<s:select headerKey="" headerValue="--- Select ---" list="states" name="yourEmployee" key="addEmployee.yourEmployee" required="true" cssClass="input"></s:select>

when i run this with server then it will generate html code, in that i am getting
value of the list and name of the list as same, like,

<select name="yourEmployee" id="AddEmployeeAction_yourEmployee" class="input">
<option value="">--- Select ---</option>
<option value="XYZ">XYZ</option> //(Here value and name are same "XYZ"
<option value="ABC">ABC</option> //(Here value and name are same "ABC"
<option value="MJJ">MJJ</option> //(Here value and name are same "MJJ"
</select>

my problem is that, i wanna set employeeId as value and employeeName as name..

**So, if anyone know about this please help me...**


**Thanks in advance....**
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

From struts2 doc
listKey -> used as key
listValue -> used as value
key -> Set the key (name, value, label) for this particular component

A.A.Anbarasu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I wanted to populate "id" as value and "employeeName" as a name <s:select> in struts 2
 
Similar Threads
Designing a shopping cart
Capturing a list of details from the UI to ActionForm
Struts 2 list box problem
h:selectOneMenu - setting the correct value
s:select and data conversion