0

Nice day it is. I have a CDI Bean with Conversation scope invoked from another xhtml, to land in a xhtml which loads a datatable. This datatable has pagination (not using lazy loading yet, just simple pagination) and the table loads data without problems. But when i click on some page or an arrow to change page, it shows "No records found". These are the files.

My CDI Bean, PaisManagedBean:

package com.saplic.fut.beans;

import java.io.Serializable;
import java.util.List;

import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;
import javax.inject.Named;

import com.saplic.fut.daos.CiudadDAO;
import com.saplic.fut.entity.Ciudad;

@Named("paisMB")
@ConversationScoped
public class PaisManagedBean implements Serializable {

    private static final long serialVersionUID = -203436251219946811L;

    @Inject
    private CiudadDAO ciudadDAO;

    private List<Ciudad> ciudades;
    private Integer idCity;

    public String loadCities() {
        ciudades = ciudadDAO.cargarCiudades();
        return "listaCiudades";
    }

    public void loadCityInfo(ActionEvent e) {
        System.out.println("The ID is " + getIdCity());
        return;
    }   

    public List<Ciudad> getCiudades() {
        return ciudades;
    }

    public void setCiudades(List<Ciudad> ciudades) {
        this.ciudades = ciudades;
    }

    public Integer getIdCity() {
        return idCity;
    }

    public void setIdCity(Integer idCity) {
        this.idCity = idCity;
    }

}

Then, this xhtml is my index. From here i just call paisMB.loadCities() and land on my datatable :

<!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"> 

<ui:composition template="/plantilla/template.xhtml">
    <ui:define name="contenido">
    <h:form>
        <p:commandButton action="#{paisMB.loadCities()}"
        value="Show cities" />
    </h:form>
    </ui:define>
 </ui:composition>
</html>

And finally the xhtml where i have the datatable, listaCiudades.xhtml:

<!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"> 

<ui:composition template="/plantilla/template.xhtml">

    <ui:define name="contenido">
    <h:form id="frm1">

        <p:dataTable id="tablita" resizableColumns="true" rowIndexVar="rowIdx"
        paginator="true" rows="10" paginatorPosition="bottom" value="#{paisMB.ciudades}"
        var="ciu" >
            <p:column headerText="Código pais">
                <p:outputLabel value="#{ciu.codigoPais}" />
            </p:column>
            <p:column headerText="Distrito">
                <p:outputLabel value="#{ciu.distrito}" />
            </p:column>
            <p:column headerText="Nombre">
                <p:outputLabel value="#{ciu.nombre}" />
            </p:column>
            <p:column headerText="Población">
                <p:outputLabel value="#{ciu.poblacion}" />
            </p:column>
            <p:column headerText="Accion">
                <p:commandLink actionListener="#{paisMB.loadCityInfo()}" ajax="false" process="frm1" value="Detail">
                    <f:setPropertyActionListener value="#{ciu.id}" target="#{paisMB.idCity}" />
                </p:commandLink>
            </p:column>
        </p:dataTable>
    </h:form>
    </ui:define>
 </ui:composition>
</html>

I tried changing to @SessionScoped instead @ConversationScoped and it works, it looks like it's ignoring @ConversationScoped because when i debug and monitor getCiudades() getter, when i click on a page, ciudades is null. It loses the value.

Also, the commandLink that is inside my datatable doesn't work. It doesn't call my method paisMB.loadCityInfo(). I've tried using action instead actionListener, and removing parameter from the method but it doesn't work.

What is happening?

Oscar Calderon
  • 883
  • 2
  • 13
  • 30

0 Answers0