raju
raju

Reputation: 35

how to iterate Set in s:iterator in Struts 2

I have a Set with list of objects, i want to iterate this set in s:iterator tag in struts 2 and access one of the property of Object. How can i achieve this?

Sample code:

class Employee{
    String name;
    String age;

    ...getters and setters...
}

...

Set<Employee> empSet = new HashSet<Employee>;
empSet.add( ...some objects)

In Jsp: I want to access employee name

<s:iterator value = "empSet">
   <property value=???(how to get employee name) >
</s:iterator>

Thanks

Upvotes: 1

Views: 7322

Answers (1)

Nate
Nate

Reputation: 2456

Iterator docs: http://struts.apache.org/2.1.6/docs/iterator.html

You want to do something like this:

<s:iterator value="empSet">
  <p>Name is: <s:property value="name"/></p>
</s:iterator>

Note that you'll need a getter for empSet on your Action class.

Upvotes: 1

Related Questions