I have a XHTML displaying rows from a dataTable having few texts columns and one image column. I have been able to export the text columns for all the records in pdf, but I am not able to export the images in the rows. I searched in lots of posts to find out a way to export the images from the rows, but failed. Please note that I am not looking for exporting a single image for header or footer, which can be handled by preProcessor attribute in the p:dataExporter tag. I found good hints/examples for exporting single image using PreProcessor in dataExport tag. The hints are working fine for me. But I was unable to find any hint/example for row-wise image export. Please help!
My technology stack: JSF2, PrimeFaces 4.0, itext-1.1.4, JDK1.8, GlassFish Server 4
My current xhtml output given below. I need to export the green ticks and red crosses to pdf.
My JSF/XHTML code:
<?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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/templates/common.xhtml">
<ui:define name="content">
<h:panelGroup id="formTitle" layout="block">
<h:outputText value="#{bundle.ListUsersTitle}"></h:outputText>
</h:panelGroup>
<h:form styleClass="jsfcrud_list_form">
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
<h:outputText escape="false" value="#{bundle.ListUsersEmpty}" rendered="#{usersController.items.rowCount == 0}"/>
<h:panelGroup rendered="#{usersController.items.rowCount > 0}">
<p:dataTable id="dtUsers" value="#{usersController.items}" var="item" scrollable="true" scrollHeight="500">
<p:column sortBy="#{item.id}">
<f:facet name="header">
<h:outputText value="#{bundle.ListUsersTitle_id}"/>
</f:facet>
<h:outputText value="#{item.id}" />
</p:column>
<p:column sortBy="#{item.userName}">
<f:facet name="header">
<h:outputText value="#{bundle.ListUsersTitle_userName}"/>
</f:facet>
<h:outputText value="#{item.userName}" />
</p:column>
<p:column sortBy="#{item.userPassword}" exportable="false">
<f:facet name="header">
<h:outputText value="#{bundle.ListUsersTitle_userPassword}"/>
</f:facet>
<h:outputText value="#{item.userPassword}" />
</p:column>
<p:column id="userActiveCol" sortBy="#{item.userActive}">
<f:facet name="header">
<h:outputText value="#{bundle.ListUsersTitle_userActive}"/>
</f:facet>
<h:graphicImage id="yesId" value="/img/Yes.png" alt="Yes" rendered="#{item.userActive == 'Y'}"/>
<h:graphicImage id="noId" value="/img/No.png" alt="No" rendered="#{item.userActive == 'N'}"/>
</p:column>
<p:column sortBy="#{item.userSource}">
<f:facet name="header">
<h:outputText value="#{bundle.ListUsersTitle_userSource}"/>
</f:facet>
<h:outputText value="#{(item.userSource == 'ORGANIZATION')?'Organization':
(item.userSource == 'VENDOR')?'Vendor':
(item.userSource == 'VENDORRESOURCE')?'Vendor Resource':
(item.userSource == 'CUSTOMER')?'Customer':'Not Known'}" />
</p:column>
<p:column sortBy="#{item.resourceId}">
<f:facet name="header">
<h:outputText value="#{bundle.ListUsersTitle_resourceId}"/>
</f:facet>
<h:outputText value="#{item.resourceId}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListUsersTitle_resourceName}"/>
</f:facet>
<h:outputText value="#{usersController.getResourceName(item)}" />
</p:column>
<p:column headerText=" " exportable="false">
<h:panelGroup styleClass="formRowAction">
<p:commandLink action="#{usersController.prepareView}" value="#{bundle.ListUsersViewLink}"/>
</h:panelGroup>
<h:panelGroup styleClass="formRowAction">
<p:commandLink action="#{usersController.prepareEdit}" value="#{bundle.ListUsersEditLink}"/>
</h:panelGroup>
<h:panelGroup styleClass="formRowAction">
<p:commandLink action="#{usersController.destroy}"
value="#{bundle.ListUsersDestroyLink}" />
</h:panelGroup>
</p:column>
</p:dataTable>
</h:panelGroup>
<br />
<h:panelGroup styleClass="formBottomActions">
<h:panelGroup>
<h:commandLink action="#{usersController.prepareCreate}" value="#{bundle.ListUsersCreateLink}"/>
</h:panelGroup>
<h:panelGroup>
<p:commandLink value="#{bundle.ExportPDF}" immediate="true" id="generatePDFId" ajax="false">
<p:dataExporter type="pdf" target="dtUsers" fileName="Users"/>
</p:commandLink>
</h:panelGroup>
<h:panelGroup>
<h:link outcome="/subMenu" value="#{bundle.SubMenuLink}"/>
</h:panelGroup>
<h:panelGroup>
<h:commandLink action="#{menuHandler.returnToMainMenu}" value="#{bundle.mainMenuLink}"/>
</h:panelGroup>
</h:panelGroup>
</h:form>
</ui:define>
</ui:composition>
</html>
PDF that is currently getting generated. The green ticks and red crosses should appear in the column "User Active".