• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Arun R Upadhya
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From struts2 doc
listKey -> used as key
listValue -> used as value
key -> Set the key (name, value, label) for this particular component
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!