0
Here’s my problem:
In the xhtml below (listDeOSs.xhtml) when I put it this way, it does not recognize the method I made in my Bean (the bean method returns a list). JSF along with primefaces is shown perfectly on the screen, only it does not return the data (No Records found).
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:commandButton value="Listar" actionListener="#{MBean.retornaOSsPorCliente}" styleClass="ui-priority-primary" />
<p:dataTable var="sza" value="#{MBean.list}">
<p:column headerText="Cliente">
<h:outputText value="#{sza.ZA_CLIENTE}" />
</p:column>
<p:column headerText="Funcionário">
<h:outputText value="#{sza.ZA_CODFUN}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
Below the screen shown that does not show the data:
On the other hand, when I use jsf with html, the code recognizes my bean’s method and consequently works (returning the data). Only it gets ugly, different from the first faces that’s beautiful.
Down with my bean:
package br.com.moriahitg.bean;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import br.com.moriahitg.dao.SZA990DAO;
/*import br.com.moriahitg.modelo.SA1990;*/
import br.com.moriahitg.modelo.SZA990;
@ManagedBean (name="MBean")
@SessionScoped
public class MBean implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
List<SZA990> list = new ArrayList<SZA990>();
public SZA990 sza;
@SuppressWarnings("unchecked")
public List<SZA990> retornaOSsPorCliente () {
SZA990DAO szadao = new SZA990DAO();
list = szadao.getOSPorCliente("000002");
return list;
}
/*
public Iterator retornaOSsPorCliente (SA1990 sa1) {
SZA990DAO szadao = new SZA990DAO();
list = szadao.getOSPorCliente(sa1.getA1_COD());
Iterator it = list.iterator();
return it;
}
*/
public List<SZA990> getList() {
return list;
}
public void setList(List<SZA990> list) {
this.list = list;
}
public SZA990 getSza() {
return sza;
}
public void setSza(SZA990 sza) {
this.sza = sza;
}
}
My faces-cofig down below:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<managed-bean>
<managed-bean-name>MBean</managed-bean-name>
<managed-bean-class>br.com.moriahitg.bean.MBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>t.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Hello Nehemiah. Which version of JSF and Primefaces you are using?
– Murilo A. Oliveira
Hello Murilo, the version is 4.0 according to pom.xml
– Neemias Carvalho
Solved people! The solution was to put ajax="false" on the commandbutton and restart everything to clear Session. A warning for beginners like me: If you’re using Session, switch to request. I say this because sometimes you run the correct code, but the previous information (the wrong one) is stored and it appears on your screen. So it gives the impression that what you’re running is still wrong.
– Neemias Carvalho