user2213180
user2213180

Reputation: 71

Display contents of a list of beans with struts2-iterator

I´m trying to display a list that constains objets of a bean. I´m using iterator tag to display the list

/*JSP*/
<s:iterator value="lInfTaq" var="res">
<tr>
    <td><s:property value="#res.numEjercicio"/></td>
    <td><s:property value="#res.numOKs()"/></td>
    <td><s:property value="#res.numKOs"/></td>
</tr>
</s:iterator>


/*ACTION*/
public class TaquitoscopioAction extends ActionSupport{
 /* . . . */
List <InformeTaquitoscopio> lInfTaq;
/* Filled the list */


/*BEAN*/
public class InformeTaquitoscopio {
private String numEjercicio;
private String numOKs;
private String numKOs;
public InformeTaquitoscopio() {
  super();
  // TODO Auto-generated constructor stub
}
public InformeTaquitoscopio(String numEjercicio, String numOKs, String numKOs) {
super();
this.numEjercicio = numEjercicio;
this.numOKs = numOKs;
this.numKOs = numKOs;
}
/*getters and setters*/
}

But the jsp doesn´t display anything. Whats wrong?

Upvotes: 1

Views: 5734

Answers (1)

Quaternion
Quaternion

Reputation: 10458

InformeTaquitoscopio must have getters for: numEjercicio, numOKs, numKOs or make the properties public. The action requires a getter for lInfTaq or that the property be public.

Then the following should work:

<s:iterator value="lInfTaq">
<tr>
    <td><s:property value="numEjercicio"/></td>
    <td><s:property value="numOKs"/></td>
    <td><s:property value="numKOs"/></td>
</tr>
</s:iterator>

Just personally speaking but I tend not to like var attributes on struts2 tags. It tell me that you are going to be covering a variable or moving it into another scope. If you are not nesting iterators you generally shouldn't need a var attribute on an iterator. It certainly is easier on the eyes this way. Assuming you understand you're working with a stack, which is pretty fundamental to struts2.

Upvotes: 1

Related Questions