File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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

Arun R Upadhya

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"

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

I agree. Here's the link:
subject: I wanted to populate "id" as value and "employeeName" as a name <s:select> in struts 2
It's not a secret anymore!