I'm trying to get that code working:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition 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"
template="/templates/default.xhtml">
<ui:define name="content">
<h:form id="form">
<p:dataTable id="clienti" var="c" value="#{clientiController.clienti}" rowKey="#{c.id}">
<p:column headerText="Ragione sociale">
<h:outputText value="#{c.ragioneSociale}" />
</p:column>
<p:column headerText="Codice fiscale">
<h:outputText value="#{c.codiceFiscale}" />
</p:column>
<p:column style="width:4%">
<p:commandButton
update=":formDialog:clienteEditDialogTable"
oncomplete="clienteEditDialog.show()"
value="Modifica"
title="Modifica">
<f:setPropertyActionListener value="#{c}" target="#{clientiController.clienteSelezionato}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:commandButton value="Aggiorna" actionListener="#{clientiController.aggiorna}" update=":form:clienti" icon="ui-icon-arrowrefresh-1-n" />
<p:commandButton value="Nuovo Cliente" actionListener="#{clientiController.nuovo}" update=":formDialog:clienteEditDialogTable" oncomplete="clienteEditDialog.show()" />
</h:form>
<p:dialog
header="Modifica Cliente"
widgetVar="clienteEditDialog"
id="clienteEditDialog"
showEffect="fade"
hideEffect="explode"
closable="true"
modal="true"
appendToBody="true">
<h:form id="formDialog">
<h:panelGrid id="clienteEditDialogTable" columns="2" cellpadding="10" style="margin:0 auto;">
<p:outputLabel for="fieldNome" value="Ragione Sociale:" />
<p:inputText id="fieldNome" value="#{clientiController.clienteSelezionato.ragioneSociale}" />
<p:outputLabel for="fieldCodice" value="Codice:" />
<p:inputText id="fieldCodice" value="#{clientiController.clienteSelezionato.codiceFiscale}" required="true" requiredMessage="Codice fiscale obbligatorio" />
</h:panelGrid>
<p:commandButton
value="Conferma modifiche"
actionListener="#{clientiController.modifica}"
update=":form:clienti"
oncomplete="clienteEditDialog.hide()"
rendered="#{clientiController.clienteSelezionato.id!=null}" />
<p:commandButton
value="Conferma nuovo cliente"
actionListener="#{clientiController.crea}"
update=":form:clienti"
oncomplete="clienteEditDialog.hide()"
rendered="#{clientiController.clienteSelezionato.id==null}" />
</h:form>
</p:dialog>
</ui:define>
</ui:composition>
By clicking on "Nuovo Cliente" I get a javascript console error:
TypeError: 'undefined' is not a function (evaluating
'clienteEditDialog.show()')
It's a naming container misunderstanding of course.
Can you help me give the right ids?
In older primefaces version one could not assign the same name for widgetVar and id of a p:dialog
Try changing id="clienteEditDialog" into id="clienteEditDialogId"
You are referencing clienteEditDialogTable from different naming container. Actual id is
:formDialog:clienteEditDialogTable, so try with it. Id can be different but I can tell you more after you give the template source code.
Related
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 current xhtml output
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".
PDF that is currently getting generated
The PrimeFaces exporter does not export images from cells only text. You will have to write a custom PDF exporter to meet your needs.
I want to implement Primefaces wizard with finish button at the bottom. Example code:
<h:form>
<p:growl id="growl" sticky="true" showDetail="true"/>
<p:wizard flowListener="#{newSensor.onFlowProcess}">
<p:tab id="personal" title="General">
<p:panel header="Sensor Details">
<p:messages />
<h:panelGrid columns="2" columnClasses="label, value">
......
<h:outputText value="Enabled " />
<h:selectBooleanCheckbox value="#{newSensor.sensor.enabled}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirm" title="Confirmation">
<p:panel header="Confirmation">
<h:panelGrid id="confirmation" columns="3" columnClasses="grid,grid,grid">
<h:panelGrid columns="2" columnClasses="label, value">
......
<h:outputText value="Age: " />
<h:outputText value="#{newSensor.sensor.enabled}" styleClass="outputLabel"/>
</h:panelGrid>
</h:panelGrid>
<p:commandButton value="Submit" actionListener="#{newSensor.save}" update="growl" process="#this"/>
</p:panel>
</p:tab>
</p:wizard>
</h:form>
Want to get this visual result:
How I can get this visual result?
I think it's best to implement your own UI for the navigation and just control when the Submit button will be displayed.
First hide the navigation bar as such:
<p:wizard showNavBar="false" widgetVar="wiz">
...
</p:wizard>
Then just create some codes for the NEXT,BACK,SUBMIT, ETC.
<p:outputPanel id="updateAsNeeded">
<h:outputLink value="#" onclick="PF('wiz').next();">Next</h:outputLink>
<h:outputLink value="#" onclick="PF('wiz').back();">Back</h:outputLink>
<p:commandButton value="Submit" rendered="#{bean.isEndReached}">Submit</p:commandButton>
</p:outputPanel>
Then you define a FlowListener to determine :
<p:wizard flowListener="#{bean.handleFlow}">
...
</p:wizard>
For your bean:
public String handleFlow(FlowEvent event) {
String currentStepId = event.getCurrentStep();
String stepToGo = event.getNextStep();
//check if stepToGo is on the last page
//endReached = true;
RequestContext.update("updateAsNeeded");
return event.getNextStep();
}
Hope this helps or guides you forward.
I want to do conditional Polling in Primefaces (Version:6.0.0).
Here is the polling code:
<p:poll interval="20" update="liveChart,chrtTC_Cnt_Status,chrtStatus" />
For Example, I am field call Status. If status value is 'In-Progress' then only polling should start. Or else it should not do polling.
Here is my field code, if this value changed to 'In-Progress' then polling should start or else not
<p:outputLabel value="Status:" />
<p:outputLabel id="lblCurrentStatus" value="#{backingBean.status}" />
Here is my Xhtml code
<h:panelGrid columns="2" width="400">
<p:outputLabel for="lblStudentName" value="Select Other StudentName: " />
<p:selectOneMenu id="lblStudentName" style="width:250px"
value="#{backingBean.selectedStudent}"
panelStyle="width:180px" effect="fade" filter="true"
filterMatchMode="startsWith">
<f:selectItem itemLabel="Select One" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{backingBean.studentItemList}" />
<p:ajax
listener="#{backingBean.OnChangeOtherStudentDropDown}"
update=":idForm:tabStatus:p1,:idForm:tabStatus:p4,growl"
process="#form" />
</p:selectOneMenu>
<p:tabView id="tabStatus">
<p:tab title="Status" id="idStatusTab">
<h:panelGrid columns="3" cellpadding="10" id="p1">
<p:growl id="growl" showDetail="true" />
<p:ajaxStatus onstart="PF('statusDialog').show()"
onsuccess="PF('statusDialog').hide()" />
<p:dialog widgetVar="statusDialog" draggable="false"
closable="false" resizable="false" showHeader="false">
<h:graphicImage value="/images/ajax-loader.gif" />
</p:dialog>
<h:panelGrid columns="2" cellpadding="5" id="p2">
<p:outputLabel value="Failed:" />
<p:outputLabel id="lblCurrentFailed"
value="#{backingBean.intCurrentFailedStudent}" />
<p:outputLabel value="Processed:" />
<p:outputLabel id="lblCurrentProcess"
value="#{backingBean.intCurrentPassedStudent}" />
<p:outputLabel value="Status:" />
<p:outputLabel id="lblCurrentStatus"
value="#{backingBean.status}" />
</h:panelGrid>
<h:panelGrid columns="2" cellpadding="10" id="p3">
<p:chart type="pie" model="#{backingBean.pieModel1}"
rendered="#{not empty backingBean.pieModel1}"
id="chrtStatus" style="width:300px;height:200px">
</p:chart>
<br />
</h:panelGrid>
</h:panelGrid>
<h:panelGrid columns="3" cellpadding="10" id="p4">
<p:poll interval="20" update="liveChart,chrtTC_Cnt_Status,chrtStatus" />
<p:chart type="line"
model="#{backingBean.lineCurrentLineChart}"
rendered="#{not empty backingBean.lineCurrentLineChart}"
id="liveChart" style="height:500px;width:500px" />
<p:chart type="bar"
model="#{backingBean.barStatusCountStudent}"
rendered="#{not empty backingBean.barStatusCountStudent}"
id="chrtTC_Cnt_Status" style="width:500px;height:500px">
<p:ajax event="itemSelect" listener="#{backingBean.itemSelect}" />
</p:chart>
</h:panelGrid>
</p:tab>
</p:tabView>
</h:form>
Solution 1:
Wrap your p:poll within h:panelGroup or h:panelGrid, set rendered="#{backingBean.status eq 'In-Progress'}" on panel and update panel on changing of status, that will reset your polling.
Solution 2:
If you want to manually start and stop the polling then you need to set autoStart="false" and add widgetVar="statusPoll" attributes on p:poll and by invoking PF('statusPoll').start(); and PF('statusPoll').stop(); on changing the value of status field.
It is working,
<h:panelGrid columns="1" id="ID_polling" rendered="#{BackingBean.status eq 'In-Progress'}">
<p:poll interval="20" update="liveChart,chrtTC_Cnt_Status,chrtStatus" />
</h:panelGrid>
When I write this Panel, Panel will display only when status = 'In-Progress' or else it will not display.
Thank you again,
As you can see i first look for a person with a first commandButton, then i select a person in the datatable and i have a second commandButton, and i'd like to switch the defaultCommand on button2 after i selected a person, how can i achieve this?
<h:form id="form"
rendered="#{security.asRole('ADMIN') or security.asRole('GESTIONNAIRE')}">
<f:event type="preRenderView" listener="#{paieAgentView.init()}" />
<p:fieldset legend="Recherche de l'agent">
<p:panelGrid columns="2">
<p:panelGrid columns="2" id="pgRechercheAgent">
<h:outputLabel value="Matricule :" />
<p:inputText id="matricule"
value="#{paieAgentView.agentSearched.matricule}">
<p:ajax process="matricule" partialSubmit="true" event="keyup" />
<h:commandButton id="boutonLigneAgent"
action="#{paieAgentView.searchLigneAgent()}"
value="Rechercher les agents" icon="ui-icon-search"
update="listAgents" immediate="true" >
<f:ajax render="#form" execute="#this" />
</h:commandButton>
<br />
</p:panelGrid>
<p:dataTable id="listAgents" var="agt"
value="#{paieAgentView.listLigneAgent}"
selection="#{paieAgentView.agentSelected}"
rowKey="#{agt.matricule}" style="margin-bottom:0"
selectionMode="single" scrollRows="20" scrollable="true"
liveScroll="true" scrollHeight="250">
<p:ajax event="rowSelect" update=":form:pgRechercheContrats" />
<p:column headerText="Matricule">
<h:outputText value="#{agt.matricule}" />
</p:column>
<p:column headerText="Nom">
<h:outputText value="#{agt.nomPat} #{agt.prenom}" />
</p:column>
</p:dataTable>
</p:panelGrid>
<p:defaultCommand target="boutonLigneAgent" />
</p:fieldset>
<p:fieldset legend="Critères de recherche">
<p:panelGrid columns="3" id="pgRechercheContrats">
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="typePeriode" value="Période de paie:" />
<p:selectOneRadio id="typePeriode"
value="#{paieAgentView.typePeriode}">
<f:selectItem itemLabel="Période de paie" itemValue="paie" />
<f:selectItem itemLabel="Période d'origine" itemValue="origine" />
</p:selectOneRadio>
</h:panelGrid>
<h:panelGrid columns="2" id="pgCalendar">
<h:outputLabel value="Date Debut : " for="calendrierDateDebut" />
<p:calendar id="calendrierDateDebut"
value="#{paieAgentView.dateDebut}" pattern="yyyy-MM-dd"
effect="slideDown" navigator="true" mode="inline"
locale="#{sessionControleur.langue}" style="moisAnSeul" />
<h:outputLabel value="Date fin : "
for="calendrierDateFin" />
<p:calendar id="calendrierDateFin"
value="#{paieAgentView.dateFin}" pattern="yyyy-MM-dd"
effect="slideDown" navigator="true" mode="inline" lang="fr"
locale="fr" style="moisAnSeul" />
</h:panelGrid>
<p:selectManyCheckbox id="gridTypesPaie"
value="#{paieAgentView.selectedTypesPaie}" columns="1"
layout="pageDirection">
<f:selectItems value="#{paieAgentView.typesPaie}" var="type"
itemLabel="#{type.label}" itemValue="#{type.value}" />
</p:selectManyCheckbox>
</p:panelGrid>
</p:fieldset>
<p:commandButton process="pgRechercheContrats"
icon="ui-icon-file-pdf" value="Editer les fiches de paie"
action="#{paieAgentView.printPaieAgent()}" update="#form"
escape="false" ajax="false"
onclick="regenererCal();this.form.target='_blank'" />
</h:form>
Make 2 defaultCommands both with rendered attribute. Rendered should check if person is selected or not and action called must be appropriete on that. since you are updating whole form every time something change this should work
<p:defaultCommand target="boutonLigneAgent" rendered="#{personIsSelected()}"/>
<p:defaultCommand target="pgRechercheContrats" rendered="#{personIsNotSelected()}"/>
I have this piece of code:
<h:body>
<h:form id="form1">
<p:menuButton value="#{msgs.settingsMenuButton}">
<p:menuitem value="#{msgs.accountsMenuItem}" url="#" update=":dlgEdit" oncomplete="_dlgEdit.show()"/>
</p:menuButton>
<p:commandButton value="Accounts" icon="ui-icon-gear"
update=":dlgEdit"
oncomplete="_dlgEdit.show()"/>
</h:form>
<p:dialog id="dlgEdit" widgetVar="_dlgEdit" modal="true" closable="true" header="Accounts">
<h:form id="frmEdit" >
<p:panelGrid id="pnlEdit" columns="2">
<p:outputLabel id="lblName" for="eName" value="Name"/>
<p:inputText id="eName" value="#{tasksBean.selectedLocation}"/>
</p:panelGrid>
</h:form>
</p:dialog>
</h:body>
The dialog is not displayed when the menuItem is selected but it works when the commandButton is pressed.
The behaviors for both are the same...
Can you support me please?
Thanks,
Andrei
Try:
oncomplete="PF('_dlgEdit').show();"