Yayotrón
Yayotrón

Reputation: 1869

Primefaces Extensions' Excel Exporter throws Property not found on type

I know this has been asked a lot. I already searched and tried multiple solutions, like this one but none of them work. Let me explain my problem:

I'm using Primefaces 4.0 with Primefaces Extensions 1.2.1. In a larger page I have this DataTable, which data I'd like to export to excel.

<p:dataTable id="t_resultados" value="#{buscarTramitesController.tablaProcesos}" var="proceso"
                             emptyMessage="No se han encontrado Trámites" 
                             paginator="true" rows="10" paginatorPosition="top"
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             rowsPerPageTemplate="5,10,50,100" lazy="true"
                             currentPageReportTemplate="Registros Totales: {totalRecords}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Página: {currentPage} de {totalPages}"
                             selection="#{buscarTramitesController.procesoSeleccionado}" selectionMode="single"
                             rowKey="#{proceso.id}" resizableColumns="true" draggableColumns="true">
                    <p:column width="80" sortBy="#{proceso.nombre}">
                        <f:facet name="header"><p:outputLabel value="Nombre:"/></f:facet>
                        <p:outputLabel value="#{proceso.nombre}"/>
                    </p:column>
                    <p:column width="80" sortBy="#{proceso.tramite.expedienteAsociado.nombre}">
                        <f:facet name="header"><p:outputLabel value="Expediente:"/></f:facet>
                        <p:outputLabel value="#{proceso.tramite.expedienteAsociado.nombre}"/>
                    </p:column>
                    <p:column width="110" sortBy="#{proceso.fechaInicio}">
                        <f:facet name="header"><p:outputLabel value="Fecha de Inicio"/></f:facet>
                        <h:outputText value="#{proceso.fechaInicio}">
                            <f:convertDateTime pattern="dd/MM/yyyy hh:mm a"/>
                        </h:outputText>
                    </p:column>
                    <p:column width="140" sortBy="#{proceso.fechaFinalizacion}">
                        <f:facet name="header"><p:outputLabel value="Fecha de Finalización"/></f:facet>
                        <h:outputText rendered="#{proceso.fechaFinalizacion eq null}" 
                                      value="Proceso en marcha">
                        </h:outputText>
                        <h:outputText rendered="#{proceso.fechaFinalizacion ne null}" value="#{proceso.fechaFinalizacion}">
                            <f:convertDateTime pattern="dd/MM/yyyy hh:mm a"/>
                        </h:outputText>
                    </p:column>
                    <p:column width="120">
                        <f:facet name="header"><p:outputLabel value="Actividad actual"/></f:facet>
                        <h:outputText value="#{buscarTramitesController.NombreActividad(proceso)}">
                        </h:outputText>
                    </p:column>
                    <p:column width="120" >
                        <f:facet name="header"><p:outputLabel value="Aceptada por"/></f:facet>
                        <h:outputText value="#{buscarTramitesController.AceptadaPor(proceso)}">
                        </h:outputText>
                    </p:column>
                    <p:column width="170">
                        <f:facet name="header"><p:outputLabel value="Última actividad completada"/></f:facet>
                        <h:outputText value="#{buscarTramitesController.UltimaCompletada(proceso)}">
                            <f:convertDateTime pattern="dd/MM/yyyy hh:mm a"/>
                        </h:outputText>
                    </p:column>
                    <p:column>
                        <f:facet name="header"><p:outputLabel value="Completada por"/></f:facet>
                        <h:outputText value="#{buscarTramitesController.CompletadaPor(proceso)}">
                        </h:outputText>
                    </p:column>
                    <p:column width="80">
                        <f:facet name="header"><p:outputLabel value="Opciones"/></f:facet>
                        <p:commandLink immediate="true" value="Ver" actionListener="#{buscarTramitesController.abrirTramite(proceso.id)}"/>
                    </p:column>
                    <p:ajax event="rowDblselect" listener="#{buscarTramitesController.abrirTramite(buscarTramitesController.procesoSeleccionado.id)}"/> 
                </p:dataTable>

And my exporter looks like this:

<p:commandButton value="Exportar a Excel" id="b_exportar" ajax="false">
<pe:exporter type="xlsx" target="t_resultados" fileName="Lista de Tramites"/>
</p:commandButton>

I have several excel exporters in my application and only that one is giving problem. When I click that button, it throws the follow exception:

javax.servlet.ServletException: /busquedas/BuscarTramites.xhtml @124,100 value="#{buscarTramitesController.NombreActividad(proceso)}": Property 'NombreActividad' not found on type com.megagroup.mgestion.web.controller.busquedas.BuscarTramitesController
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)

It's the first method in that table which it tries to call.

These methods all looks the same, receives a Proceso (which is the object that's being displayed in the datatable) and returns a String:

My backing bean looks like this:

private Tarea ultimaTareaCompletada(Proceso proceso) {
    List<Tarea> tareas = proceso.getTareas();
    if (tareas == null || tareas.isEmpty()) {
        return null;
    }
    List<Tarea> tareasCompletadas = new ArrayList<>();
    for (Tarea tarea : tareas) {
        if (tarea.getEstado().equals(EstadoTarea.COMPLETADA)) {
            tareasCompletadas.add(tarea);
        }
    }
    if (tareasCompletadas.isEmpty()) {
        return null;
    }
    Collections.sort(tareasCompletadas, new Comparator<Tarea>() {
        @Override
        public int compare(Tarea t1, Tarea t2) {
            if (t2.getFechaFinalizacion() == null) {
                return 999;
            }
            if (t1.getFechaFinalizacion() == null) {
                return 0;
            }
            return t2.getFechaFinalizacion().compareTo(t1.getFechaFinalizacion());
        }
    });
    return tareasCompletadas.get(0);
}

public String UltimaCompletada(Proceso proceso) {
    Tarea tarea = ultimaTareaCompletada(proceso);
    if (tarea == null) {
        return PROCESO_SIN_TAREAS;
    } else if (tarea.getTipoTarea() == null) {
        return TAREA_SIN_ACTIVIDAD;
    } else if (tarea.getTipoTarea().getNombre() == null || tarea.getTipoTarea().getNombre().isEmpty()) {
        return ACTIVIDAD_SIN_NOMBRE;
    } else {
        return tarea.getTipoTarea().getNombre();
    }
}

public String CompletadaPor(Proceso proceso) {
    Tarea tarea = ultimaTareaCompletada(proceso);
    if (tarea == null) {
        return PROCESO_SIN_TAREAS;
    } else if (tarea.getNombreUsuario() == null) {
        return COMPLETADA_SIN_USUARIO;
    } else {
        return tarea.getNombreUsuario();
    }
}

private Tarea actividadActual(Proceso proceso) {
    if (proceso.getTareas() == null || proceso.getTareas().isEmpty()) {
        return null;
    }
    return proceso.getTareas().get(proceso.getTareas().size() - 1);
}

public String AceptadaPor(Proceso proceso) {
    Tarea tarea = actividadActual(proceso);
    if (tarea == null) {
        return PROCESO_SIN_TAREAS;
    }
    if (tarea.getNombreUsuario() == null || tarea.getNombreUsuario().isEmpty()) {
        return SIN_ACEPTAR;
    }
    return tarea.getNombreUsuario();
}

public String NombreActividad(Proceso proceso) {
    Tarea tarea = actividadActual(proceso);
    if (tarea == null) {
        return PROCESO_SIN_TAREAS;
    }
    if (tarea.getTipoTarea().getNombre() == null || tarea.getTipoTarea().getNombre().isEmpty()) {
        return ACTIVIDAD_SIN_NOMBRE;
    }
    return tarea.getTipoTarea().getNombre();
}

I though it was the methods' name, I already tried renaming them like that: getNombreActividad, nombreActividad, NombreActividad, getnombreActividad, but none of them worked. That problem is only showing when I click the export to excel button, the table display successful all the information from these methods.

Any help would be appreciated, thanks!

Upvotes: 1

Views: 1089

Answers (1)

Kukeltje
Kukeltje

Reputation: 12337

The exporter only accepts valueExpressions afaik and not methodExpressions. ValueExpressions consist of getters and setters of properties and getters do not accept parameters. So the resolving of the property fails as expected

Upvotes: 2

Related Questions