1
votes

I am currently developing an application with JPA2, Spring 3, MyFaces 2.1 and Primefaces 4.0 RC1.

I developed a simple page with one datatable using pagination feature of primefaces, but when I click on page number (bottom or header), it simply doesn't work. No exception or javascript error is shown.

I've tested both in Chrome and Firefox. Same problem.

Here my code:

@ManagedBean
@ViewScoped
public class MeusCelularesTitularMB extends AbstractMB implements Serializable {

    private static final long serialVersionUID = 5446365969371398743L;
    private static final Logger logger = LogManager.getLogger(MeusCelularesTitularMB.class);

    private CadastroGeral loggedUser;
    private List<LinhaCelularTitular> listaCelularesTitular;

    @PostConstruct
    public void init() {
    try {
        this.loggedUser = getCadastroGeralService().loadUser(getAuthenticatedUser());
        this.listarMeusCelularesTitular();
    } catch (ServiceException e) {
        logger.error("Erro ao consultar banco de dados", e);
        throw new RuntimeException(e);
    }
    }

    private void listarMeusCelularesTitular() {
    try {
        this.listaCelularesTitular = getLinhaCelularTitularSevice().getLinhasCelularesPorReponsavel(this.loggedUser.getMatricula());
    } catch (ServiceException e) {
        logger.error("Erro ao consultar banco de dados", e);
        throw new RuntimeException(e);
    }
    }

    private static CadastroGeralService getCadastroGeralService() {
    return Faces.evaluateExpressionGet("#{cadastroGeralService}");
    }

    private static LinhaCelularTitularService getLinhaCelularTitularSevice() {
    return Faces.evaluateExpressionGet("#{linhaCelularTitularService}");
    }

    public List<LinhaCelularTitular> getListaCelularesTitular() {
    return listaCelularesTitular;
    }

    public void setListaCelularesTitular(List<LinhaCelularTitular> listaCelularesTitular) {
    this.listaCelularesTitular = listaCelularesTitular;
    }
}

And the XHTML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="../../templates/template.xhtml">
        <ui:define name="content">
            <h:outputStylesheet library="css"  name="meusCelulares.css" />

            <h:form id="meusCelularesTitulares">
                <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>

                <h2>Celulares - Titular</h2>
                <p:dataTable id="tblLinhaCelularesTitulares"
                             var="celTitular"
                             widgetVar="wdgLinhaCelularesTitulares"
                             value="#{meusCelularesTitularMB.listaCelularesTitular}"
                             rowKey="#{celTitular.id}"
                             paginator="true"
                             rows="10"
                             rowsPerPageTemplate="5,10,15"
                             emptyMessage="Nenhum celular encontrado na Base de Dados">

                    <p:column>
                        <f:facet name="header">  
                            <h:outputText value="Ações" />  
                        </f:facet>

                        <h:outputText value="A B C" />
                    </p:column>

                    <p:column styleClass="colunaCentralizada">
                        <f:facet name="header">  
                            <h:outputText value="Código DDD" />  
                        </f:facet>

                        <h:outputText value="#{celTitular.codigoDDD}" />
                    </p:column>

                    <p:column styleClass="colunaCentralizada">
                        <f:facet name="header">  
                            <h:outputText value="Número" />
                        </f:facet>

                        <h:outputText value="#{celTitular.numeroLinha}" />
                    </p:column>

                    <p:column>
                        <f:facet name="header">  
                            <h:outputText value="Nome" />  
                        </f:facet>

                        <h:outputText value="#{celTitular.responsavel.nome}" />
                    </p:column>
                </p:dataTable>
            </h:form>
        </ui:define>
    </ui:composition>
</html>

If you need some more information, please let me know.

1
Have you tried the same thing in PF 3.5? You are using a RC version, after all...patstuart
Yes. Doesn't work too. It's curious, because I have other page with another MB and works fine. No matter what version, 3.5 or 4.0RC.humungs
Please minimize your code content till still you get the error. What are that private static methods inside your bean supposed to do? For your table, I don't think rowsPerPageTemplate and emptyMessage attributes are relevant.Xtreme Biker
@XtremeBiker, your hint was very very important! Found my mistake. I've started removing rowsPerPageTemplate and emptyMessage. No success. Then I removed <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/> and it worked. So I realized my mistake. The dialog statusDialog was missing! I added the dialog and worked! Sorry for this stupid question!humungs
OK, don't worry. Just when something is not working first of all try to isolate the problem, if not success, ask it ;-)Xtreme Biker

1 Answers

1
votes

Found the solution! Thanks to @XtremeBiker for the hints.

The <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/> is referencing a dialog box that I forgot to add in the XHTML. So I added the code below and it worked.

<p:dialog modal="true" 
          widgetVar="statusDialog"
          header="Aguarde..."
          draggable="false"
          closable="false"
          resizable="false"
          width="245"
          height="25" >
    <div align="center">
        <p:graphicImage value="/resources/images/ajax-loader.gif" />
    </div>
</p:dialog>

I use this code to block screen when a ajax request is processing.

Thanks again.