Primefaces doesn’t see the methods of my class

Asked

Viewed 1,134 times

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:

Tela não mostrando os dados

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.

Reconhece o método retornaOsPorCliente

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?

  • Hello Murilo, the version is 4.0 according to pom.xml

  • 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.

1 answer

1


Tries to remove the <managed-bean>...</managed-bean> faces-config.xml

<?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">

</faces-config>

The @Managedbean annotation plays the role of pointing the class as a manageable bean. Also try to remove the property (name="Mbean") from @Managedbean. By default, on the screen JSF will display your BEAN with the minuscule class name #{mBean.metodo()}.

The first faces didn’t recognize the methods because you didn’t add the methods in the faces-config along with your bean. This is why you only use the @managedBean annotation and not map your Ben in the faces-config. Because with the annotation the already solves these problems of mapping.

Also, on your button <p:commandButton value="Listar" actionListener="#{MBean.retornaOSsPorCliente}" styleClass="ui-priority-primary" update="myDataTable" />, recommend that you put an ID for your Datatable and have it update this id update="myDataTable" on the button.

  • Thank you Murilo! I will follow your recommendations!

  • For nothing Nehemiah. Anything is but calling :-)

  • I mean that if I just put the @managedBean annotation, it will also add the methods?

  • Yes, that’s right. The public methods "public" the jsf/xhtml screen will be able to see, but private methods will not be seen by the jsf/xhtml screen.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.