Hello everyone, I'm starting JSF and I've run into a problem that's driving me crazy.
I have a class info_person. Another PersonaBean class. A page xhtml ShowTablaPersonas.xhtml.
The final intention is that you connect to a database and read all the records in the database, put it in an ArrayList, then show this arrayList in the xhtml page.
But I wanted to start with something simpler. to see if the mechanism works. here the code that I have
public class Info_Persona {
private int num1;
private int num2;
private int num3;
public Info_Persona(int num1, int num2, int num3) {
this.num1 = num1;
this.num2 = num2;
this.num3 = num3;
}
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}
public int getNum3() {
return num3;
}
public void setNum3(int num3) {
this.num3 = num3;
}
@Override
public String toString() {
return "Info_Persona [num1=" + num1 + ", num2=" + num2 + ", num3=" + num3 + "]";
}
}
For the ManagedBean class in faces-config.xml
<managed-bean>
<managed-bean-name>PersonaBean</managed-bean-name>
<managed-bean-class>paq_Persona.PersonaBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
PersonaBean.java
public class PersonaBean {
static List<Info_Persona> listaPersona = new ArrayList<>();
public void listarPers() {
int num1 = 0;
int num2 = 1;
int num3 = 2;
while (num1 < 3) {
Info_Persona per = new Info_Persona(num1, num2, num3);
listaPersona.add(per);
num1++;
num2++;
num3++;
}
}
}
The xhtml page: ShowPersona.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<h1>JSF 2.0 + JDBC Example</h1>
<h:dataTable value="#{personaBean.listaPersona()}" var="tempPers"
styleClass="order-table" headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row">
<h:column>
<f:facet name="header">
num1
</f:facet>
#{tempPers.num1}
</h:column>
<h:column>
<f:facet name="header">
num2
</f:facet>
#{tempPers.num2}
</h:column>
<h:column>
<f:facet name="header">
num3
</f:facet>
#{tempPers.num3}
</h:column>
</h:dataTable>