I made my code like de PF Showcase, but it does't works... When i click my commandLink nothing happens. Anyone can help me? I already added Apache POI and iText.
<h:form id="form">
<p:commandButton value="Novo" icon="ui-icon-document"
actionListener="#{controleBean.novoReservatorio()}" process="#this"
update="dataTable reservatorio-dialog"
oncomplete="PF('reservatorioDialog').show()" class="botaoDataTable">
<p:resetInput target="reservatorio-dialog" />
</p:commandButton>
<p:commandButton icon="ui-icon-pencil" id="btnEditar" title="Editar"
disabled="#{controleBean.reservatorio == null}"
class="botaoDataTable" process="#this" update="dataTable :form"
oncomplete="PF('reservatorioDialog').show()">
<p:resetInput target="reservatorio-dialog" />
<f:setPropertyActionListener target="#{controleBean.reservatorio}"
value="#{controleBean.reservatorioSelecao}" />
</p:commandButton>
<p:commandButton icon="ui-icon-trash" id="btnExcluir"
title="Excluir" disabled="#{controleBean.reservatorio == null}"
class="botaoDataTable" action="#{controleBean.excluirReservatorio}"
process="#this" update="dataTable btnExcluir btnEditar" />
<p:dataTable var="r" value="#{controleBean.reservatorios}"
paginator="true" rows="30" id="dataTable"
emptyMessage="Nenhum Reservatorio Cadastrado"
paginatorPosition="bottom"
selection="#{controleBean.reservatorioSelecao}"
selectionMode="single" rowKey="#{r.idReservatorio}">
<p:ajax event="rowSelect"
update=":form:btnEditar :form:btnExcluir" />
<p:ajax event="rowUnselect"
update=":form:btnEditar :form:btnExcluir" />
<p:column headerText="Nome">
<h:outputText value="#{r.nomeReservatorio}" />
</p:column>
<p:column headerText="Capacidade (Lt)">
<h:outputText value="#{r.capacidadeReservatorio}" />
</p:column>
<p:column headerText="Tipo">
<h:outputText value="#{r.tipoReservatorio}" />
</p:column>
<p:column headerText="Observação">
<h:outputText value="#{r.obsReservatorio}" />
</p:column>
</p:dataTable>
<p:commandLink>
<p:graphicImage library="img" name="xlsx.png" width="32" title="Exportar para Excel"/>
<p:dataExporter type="xls" target="dataTable" fileName="Relatorio" />
</p:commandLink>
<h:commandLink>
<p:graphicImage library="img" name="pdf.png" width="37" title="Exportar para PDF"/>
<p:dataExporter type="pdf" target="dataTable" fileName="Relatorio"/>
</h:commandLink>
<p:commandButton value="Exportar para PDF" ajax="false">
<p:dataExporter type="pdf" target=":form:dataTable" fileName="dataTable" />
</p:commandButton>
<p:dialog header="Reservatório" widgetVar="reservatorioDialog"
id="reservatorio-dialog" resizable="false" modal="true"
closeOnEscape="true">
<p:messages style="font-size:70%;" />
<p:panelGrid styleClass="semBorda">
<p:row>
<p:column>
<h:outputLabel for="nomeReservatorio" value="* Nome: "
class="componentePF label" />
</p:column>
<p:column>
<p:inputText id="nomeReservatorio" required="true"
value="#{controleBean.reservatorio.nomeReservatorio}"
requiredMessage="É necessário atribuir um nome à reservatorio"
class="componentePF text" />
</p:column>
</p:row>
<p:row>
<p:column>
<h:outputLabel for="capacidadeReservatorio"
value="* Capacidade (Lt): " class="componentePF label" />
</p:column>
<p:column>
<p:spinner id="capacidadeReservatorio" size="30"
value="#{controleBean.reservatorio.capacidadeReservatorio}"
min="0" stepFactor="1" required="true"
requiredMessage="É necessário atribuir uma capacidade à reservatorio"
class="componentePF text" />
</p:column>
</p:row>
<p:row>
<p:column>
<h:outputLabel for="tipoReservatorio"
value="* Tipo de Reservatório: " class="componentePF label" />
</p:column>
<p:column>
<p:selectOneMenu id="tipoReservatorio" style="font-size:75% !important;"
value="#{controleBean.reservatorio.tipoReservatorio}"
class="componentePF text bold" required="true"
requiredMessage="É necessário atribuir um tipo ao reservatório">
<f:selectItem itemLabel="Escolha um Tipo para o Reservatório"
noSelectionOption="true" />
<f:selectItem itemLabel="Escoamento" itemValue="Escoamento" />
<f:selectItem itemLabel="Reserva" itemValue="Reserva" />
</p:selectOneMenu>
</p:column>
</p:row>
<p:row>
<p:column>
<h:outputLabel for="obsReservatorio" value="Observação: "
class="componentePF label" />
</p:column>
<p:column>
<p:inputText id="obsReservatorio"
value="#{controleBean.reservatorio.obsReservatorio}"
class="componentePF text" />
</p:column>
</p:row>
<p:row>
<p:column colspan="2">
<p:commandButton value="Cadastrar" icon="ui-icon-disk"
action="#{controleBean.cadastrarReservatorio}"
id="cadastrarReservatorio" ajax="false"
class="componentePF button" />
</p:column>
</p:row>
</p:panelGrid>
</p:dialog>
</h:form>
The first <p:commandLink> doesn't work be cause it sends an ajax request. Just add ajax="false" to solve the problem.
See https://stackoverflow.com/a/7740280/1980659 for the root cause explanation.
With what you provided the two other buttons should work.
Related
I have the following xhtml:
<f:metadata>
<f:viewParam name="livroId" value="#{livroBean.livro.id}" />
<f:viewAction action="#{livroBean.carregarLivroPelaId}"
if="#{param.livroId != null}" />
</f:metadata>
<ui:define name="titulo">
<p:outputPanel>Novo Livro</p:outputPanel>
</ui:define>
<ui:define name="conteudo">
<h:form>
<p:messages id="messages" />
<p:fieldset legend="Dados do Livro">
<p:panelGrid columns="2">
<p:outputLabel value="Titulo:" for="titulo" />
<p:inputText id="titulo" value="#{livroBean.livro.titulo}"
required="true" requiredMessage="Título obrigatório"
validatorMessage="Título não pode ser superior a 40">
<f:validateLength maximum="40" />
<f:ajax event="blur" render="messages" />
</p:inputText>
<p:outputLabel value="ISBN:" for="isbn" />
<p:inputMask id="isbn" value="#{livroBean.livro.isbn}"
validator="#{livroBean.comecaComDigitoUm}"
mask="999-9-99-999999-9" />
<p:outputLabel value="Preço:" for="preco" />
<p:inputText id="preco" value="#{livroBean.livro.preco}" />
<p:outputLabel value="Data de Lançamento:" for="dataLancamento" />
<p:calendar id="dataLancamento"
value="#{livroBean.livro.dataLancamento.time}"
pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo" mask="true" />
</p:panelGrid>
</p:fieldset>
<br />
<p:fieldset legend="Dados do Autor">
<p:panelGrid columns="4">
<p:outputLabel value="Selecione Autor:" for="autor" />
<p:selectOneMenu value="#{livroBean.autorId}" id="autor">
<f:selectItems value="#{livroBean.autores}" var="autor"
itemLabel="#{autor.nome}" itemValue="#{autor.id}" />
</p:selectOneMenu>
<p:commandButton value="Gravar Autor"
action="#{livroBean.gravarAutor}" process="#this autor"
update="tabelaAutores" />
<p:commandLink value="ou cadastrar novo autor"
action="#{livroBean.formAutor}" immediate="true" update="#all" />
</p:panelGrid>
<p:dataTable value="#{livroBean.autoresDoLivro}" var="autor"
id="tabelaAutores" emptyMessage="Nenhum autor">
<p:column>
<h:outputText value="#{autor.nome}" />
</p:column>
<p:column>
<p:commandLink value="X"
action="#{livroBean.removerAutorDoLivro(autor)}"
update="tabelaAutores" process="#this" />
</p:column>
</p:dataTable>
</p:fieldset>
<br />
<h:panelGrid style="margin: 0 auto">
<p:commandButton value="Gravar" action="#{livroBean.gravar}"
process="#form" update="#form :formTabelaLivros:tabelaLivros" />
</h:panelGrid>
</h:form>
<br />
<h:form id="formTabelaLivros">
<p:dataTable value="#{livroBean.livros}" var="livro"
id="tabelaLivros" paginator="true" rows="5">
<f:facet name="header">Livros</f:facet>
<p:column headerText="Título" sortBy="#{livro.titulo}"
filterBy="#{livro.titulo}" filterMatchMode="startsWith">
<h:outputText value="#{livro.titulo}" />
</p:column>
<p:column headerText="ISBN" sortBy="#{livro.isbn}">
<h:outputText value="#{livro.isbn}" />
</p:column>
<p:column headerText="Preço" sortBy="#{livro.preco}">
<h:outputText value="#{livro.preco}">
<f:convertNumber type="currency" pattern="R$ #0.00"
currencySymbol="R$" locale="pt_BR" />
</h:outputText>
</p:column>
<p:column headerText="Data" sortBy="#{livro.dataLancamento.time}">
<h:outputText value="#{livro.dataLancamento.time}">
<f:convertDateTime pattern="dd/MM/yyyy"
timeZone="America/Sao_Paulo" />
</h:outputText>
</p:column>
<p:column headerText="Alterar">
<h:commandLink value="Alterar" action="#{livroBean.carregar(livro)}" />
</p:column>
<p:column headerText="Remover">
<h:commandLink value="Remover" action="#{livroBean.remover(livro)}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
The h:commandLink "Remover" is actually removing the object from my database, but is not updating the DataTable. I've already set process="#form" update="#form", but it doesn't help.
It was actually working fine before, and it suddenly stopped (I didn't modify anything related to my bean).
EDIT:
I changed it to a CommandButton, as below:
<p:column headerText="Remover">
<p:commandButton icon="fa fa-fw fa-remove" actionListener="#{livroBean.remover(livro)}" process="#form" update="#form" />
</p:column>
But still no results... The button works, it removes the entry from my database, but it does not updates the datatable. Tried with action= as well.
I have the following code in a xhtml file. After clicking the command button to save, it doesn't:
<p:tab id="bookingTab" title="Booking Information">
<p:panelGrid id="bookingGrid" columns="4">
<f:facet name="header">
#{bundle.CreateOrdrBookingTitle}
</f:facet>
<h:outputLabel value="#{bundle.CreateOrdrBookingLabel_number}"
for="number" />
<p:inputText id="number" value="#{ordrBookingController.selected.number}"
title="#{bundle.CreateOrdrBookingTitle_number}" required="true"
requiredMessage="Please enter Booking Number" />
<h:outputLabel value="#{bundle.CreateOrdrBookingLabel_ponumber}"
for="ponumber" />
<p:inputText id="ponumber"
value="#{ordrBookingController.selected.ponumber}" title="#{bundle.CreateOrdrBookingTitle_ponumber}"
required="true" requiredMessage="Please enter Booking PO Number" />
<h:outputLabel value="#{bundle.CreateOrdrBookingLabel_bookingDate}"
for="date" />
<p:calendar id="bookingDate" readonlyInput="true"
pattern="dd/MM/yyyy HH:mm:ss" value="#{ordrBookingController.selected.bookingDate}"
title="#{ordrBookingController.selected.bookingDate}" required="true"
requiredMessage="Please enter Booking Date">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
</p:calendar>
<h:outputLabel value="#{bundle.CreateOrdrBookingLabel_cost}"
for="cost" />
<p:inputText id="cost" value="#{ordrBookingController.selected.cost}"
title="#{bundle.CreateOrdrBookingTitle_cost}" required="true"
requiredMessage="Please enter Booking Cost" />
<h:outputLabel value="Contact Person" for="contactname" />
<p:inputText id="contactname"
value="#{ordrBookingController.selected.contactName}" title="Contact Name"
required="true" requiredMessage="Please enter Contact Name" />
<h:outputLabel value="Contact Number" for="contactnumber" />
<p:inputText id="contactnumber"
value="#{ordrBookingController.selected.contactNumber}" title="Contact Number"
required="true" requiredMessage="Please enter Contact Number" />
<h:outputLabel value="Comment" for="comment" />
<p:inputTextarea id="comment"
value="#{ordrBookingController.selected.comment}" title="Comment"
required="true" requiredMessage="Please enter a comment" />
<h:outputLabel value="Email List" />
<p:selectCheckboxMenu value="#{ordrBookingController.selectedUsrs}"
id="emailList" label="Select Users to Email" filter="true"
filterMatchMode="startsWith" panelStyle="width:420px" required="true"
requiredMessage="Please supply users that need to be emailed">
<f:selectItems value="#{usrController.itemsAvailableSelectManyEmail}" />
</p:selectCheckboxMenu>
<f:facet name="footer">
<p:commandButton action="#{ordrBookingController.create}"
process="bookingGrid" value="#{bundle.CreateOrdrBookingSaveLink}"
icon="ui-icon-check" ajax="true" immediate="false"
update="bookingTable bookingGrid :bookingForm:messagePanel">
<f:setPropertyActionListener
target="#{ordrBookingController.selected.ordr}" value="#{ordrController.selected}" />
<f:setPropertyActionListener
target="#{ordrBookingController.selected.active}" value="#{true}" />
</p:commandButton>
</f:facet>
</p:panelGrid>
<br></br>
<p:dataTable id="bookingTable"
value="#{ordrController.selected.ordrBookingList}" var="bookingItem"
rowKey="#{bookingItem.id}" paginator="true" rows="10"
filteredValue="#{ordrBookingController.filteredItems}">
<f:facet name="header">
#{bundle.ListOrdrBookingTitle}
</f:facet>
<p:column headerText="#{bundle.ListOrdrBookingTitle_id}"
sortBy="#{bookingItem.id}">
#{bookingItem.id}
</p:column>
<p:column headerText="#{bundle.ListOrdrBookingTitle_number}"
sortBy="#{bookingItem.number}">
#{bookingItem.number}
</p:column>
<p:column headerText="#{bundle.ListOrdrBookingTitle_ponumber}"
sortBy="#{bookingItem.ponumber}">
#{bookingItem.ponumber}
</p:column>
<p:column headerText="#{bundle.ListOrdrBookingTitle_bookingDate}"
sortBy="#{bookingItem.bookingDate}">
<h:outputText value="#{bookingItem.bookingDate}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
</h:outputText>
</p:column>
<p:column headerText="#{bundle.ListOrdrBookingTitle_cost}"
sortBy="#{bookingItem.cost}">
R
<h:outputText value="#{bookingItem.cost}">
<f:convertNumber pattern="#0.00" />
</h:outputText>
</p:column>
<p:column headerText="Contact" sortBy="#{bookingItem.ponumber}">
#{bookingItem.contactName}
</p:column>
<p:column headerText="Contact Number" sortBy="#{bookingItem.contactNumber}">
#{bookingItem.contactNumber}
</p:column>
<p:column headerText="Comment" sortBy="#{bookingItem.comment}">
#{bookingItem.comment}
</p:column>
<p:column headerText="User" sortBy="#{bookingItem.createUsr}"
rendered="#{bookingItem.createDate == bookingItem.updateDate}">
#{bookingItem.createUsr}
</p:column>
<p:column headerText="Created Date" sortBy="#{bookingItem.createDate}"
rendered="#{bookingItem.createDate == bookingItem.updateDate}">
<h:outputText value="#{bookingItem.createDate}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
</h:outputText>
</p:column>
<p:column headerText="User" sortBy="#{bookingItem.updateUsr}"
rendered="#{bookingItem.createDate != bookingItem.updateDate}">
#{bookingItem.updateUsr}
</p:column>
<p:column headerText="Update Date" sortBy="#{bookingItem.updateDate}"
rendered="#{bookingItem.createDate != bookingItem.updateDate}">
<h:outputText value="#{bookingItem.updateDate}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
</h:outputText>
</p:column>
<p:column>
<p:commandButton value="Edit" process="#this" ajax="true"
update=":bookingForm:tabView:bookingGrid" rendered="#{bookingItem.active eq true}">
<f:setPropertyActionListener target="#{ordrBookingController.selected}"
value="#{bookingItem}" />
</p:commandButton>
<p:commandButton action="#{ordrBookingController.create}"
process="#this" value="Cancel" ajax="true" immediate="false"
update="bookingTable :bookingForm:messagePanel" rendered="#{bookingItem.active eq true}">
<f:setPropertyActionListener target="#{ordrBookingController.selected}"
value="#{bookingItem}" />
<f:setPropertyActionListener
target="#{ordrBookingController.selected.active}" value="#{false}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:tab>
The p:dataTable bookingTable must be update and other listed on the update attribute. The other tables are being updated, but the bookingTable is not. What is it that is wrong here.
I saw this problem here many times but it doesn't help me.
I have the first dataTable with id:servers and I can do right click over a row and a contextMenu appears. I can click in Show Process and I get a second dataTable with id:processes.
But here is the problem, instead of showing the new dataTable I get,
javax.faces.FacesException: DataModel must implement
org.primefaces.model.SelectableDataModel when selection is enabled or
you need to define rowKey attribute
But I have defined rowKey in both dataTable
I have this code:
<h:form id="form" onkeypress="return event.keyCode != 13">
<!-- <p:messages id="msgs" /> -->
<p:growl id="msgs" showDetail="true" sticky="true" autoUpdate="true" />
<!-- Context menu for servers table. -->
<p:contextMenu for="servers">
<p:menuitem value="Show processes" update="form" icon="ui-icon-search" actionListener="#{homeBean.findLSRunningProcesses}" styleClass="homeIE"/>
</p:contextMenu>
<!-- Context menu for processes table. -->
<p:contextMenu for="processes">
<p:menuitem styleClass="homeIE" update="#form" value="Stop Process" icon="ui-icon-stop" oncomplete="stopDialog.show()"/>
</p:contextMenu>
<!-- Servers table. -->
<p:dataTable id="servers" var="server" value="#{homeBean.serverList}" paginator="true" rows="10"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" widgetVar="serversTable" rowKey="#{server.adminFQDN}"
selection="#{homeBean.selectedLogicalServer}" selectionMode="single" emptyMessage="No servers found with given criteria">
<f:facet name="header">
<h:outputText value="Servers" />
</f:facet>
<p:column filterBy="#{server.ASSETID}" filterMatchMode="contains" sortBy="#{server.ASSETID}" headerText="ASSETID">
<h:outputText value="#{server.ASSETID}" />
</p:column>
<p:column filterBy="#{server.adminFQDN}" filterStyle="width:240px;" filterMatchMode="contains" sortBy="#{server.adminFQDN}" headerText="FQDN">
<h:outputText value="#{server.adminFQDN}" />
</p:column>
<p:column filterBy="#{server.adminIP}" filterMatchMode="contains" sortBy="#{server.adminIP}" headerText="Admin IP">
<h:outputText value="#{server.adminIP}" />
</p:column>
<p:column filterBy="#{server.delivery}" filterMatchMode="exact" sortBy="#{server.delivery}" headerText="Delivery">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('serversTable').filter()">
<f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="false" />
<f:selectItems label="#{homeBean.deliveries}" value="#{homeBean.deliveries}" />
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{server.delivery}" />
</p:column>
<p:column filterBy="#{server.environment}" filterMatchMode="exact" sortBy="#{server.environment}" headerText="Environment">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('serversTable').filter()">
<f:selectItem itemLabel="Select One" noSelectionOption="true" itemValue="#{null}"/>
<f:selectItems value="#{homeBean.environments}" />
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{server.environment}" />
</p:column>
<p:column filterBy="#{server.function}" filterMatchMode="exact" sortBy="#{server.function}" headerText="Function">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('serversTable').filter()">
<f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{homeBean.functions}" />
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{server.function}" />
</p:column>
<p:column filterBy="#{server.osVersion}" filterMatchMode="contains" sortBy="#{server.osVersion}" headerText="OS VERSION">
<h:outputText value="#{server.osVersion}" />
</p:column>
<p:column filterBy="#{server.os}" filterMatchMode="contains" sortBy="#{server.os}" headerText="OS">
<h:outputText value="#{server.os}" />
</p:column>
</p:dataTable>
<!-- Panel containing processes tables. -->
<p:panelGrid id="serverProcesses" styleClass="group-user-selection-table" rendered="#{homeBean.showSelectionPanel}">
<f:facet name="header">
<p:row>
<p:column>
<h:outputText value="#{homeBean.selectedLogicalServer.adminFQDN}" />
</p:column>
</p:row>
</f:facet>
<p:row>
<!--Processes table. -->
<p:column>
<p:dataTable id="processes" var="process" value="#{homeBean.processesList}" filteredValue="#{homeBean.filteredProcesses}"
selection="#{homeBean.selectedProcesses}" paginator="true" rows="15" rowKey="#{process.owner}"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="15,20,25,30" selectionMode="single" emptyMessage="No processses found with given criteria">
<f:facet name="header">
<h:outputText value="Processes" />
</f:facet>
<p:column name="owner" filterBy="#{process.owner}" filterMatchMode="contains" sortBy="#{process.owner}" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'DESCRIPTION' : 'OWNER'}">
<h:outputText value="#{process.owner}" />
</p:column>
<p:column name="pid" filterBy="#{process.pid}" filterMatchMode="exact" sortBy="#{process.owner}" headerText="PID">
<h:outputText value="#{process.pid}" />
</p:column>
<p:column name="ppid" filterBy="#{process.ppid}" filterMatchMode="exact" sortBy="#{process.ppid}" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'TYPE' : 'PPID'}">
<h:outputText value="#{process.ppid}" />
</p:column>
<p:column name="c" filterBy="#{process.c}" filterMatchMode="exact" sortBy="#{process.c}" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'STATE' : 'C'}">
<h:outputText value="#{process.c}" />
</p:column>
<p:column name="stime" filterBy="#{process.stime}" filterMatchMode="contains" sortBy="#{process.stime}" headerText="STIME" rendered="#{!(homeBean.selectedLogicalServer.os eq 'Windows')}">
<h:outputText value="#{process.stime}" />
</p:column>
<p:column name="tty" filterBy="#{process.tty}" filterMatchMode="contains" sortBy="#{process.tty}" headerText="TTY" rendered="#{!(homeBean.selectedLogicalServer.os eq 'Windows')}">
<h:outputText value="#{process.tty}" />
</p:column>
<p:column name="time" filterBy="#{process.time}" filterMatchMode="contains" sortBy="#{process.time}" headerText="TIME" rendered="#{!(homeBean.selectedLogicalServer.os eq 'Windows')}">
<h:outputText value="#{process.time}" />
</p:column>
<p:column name="cmd" filterBy="#{process.cmd}" filterMatchMode="contains" sortBy="#{process.cmd}" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'NAME' : 'CMD'}">
<h:outputText value="#{process.cmd}" />
</p:column>
</p:dataTable>
</p:column>
</p:row>
</p:panelGrid>
<p:dialog header="Stop Process" widgetVar="stopDialog" minHeight="40" styleClass="dialogPosition">
<h:outputText value="You are going to stop the process "/>
<h:outputText value="#{homeBean.selectedProcesses.cmd}"/>
<h:outputText value="with PID"/>
<h:outputText value="#{homeBean.selectedProcesses.pid}"/>
<br /><br /><br /><br />
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" style="float:left" onclick="stopDialog2.show();stopDialog.hide();" actionListener="#{homeBean.attrListener}">
<f:attribute name="processPID" value="#{process.pid}" />
</p:commandButton>
<p:commandButton value="NO" onclick="stopDialog.hide()" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" style="float:right"/>
</p:dialog>
<p:dialog header="Stop Process" widgetVar="stopDialog2" minHeight="40" styleClass="dialogPosition">
<h:outputText value="You are going to send an email to:"/>
<br />
<h:outputText value="#{homeBean.email}"/>
<br /><br /><br />
<p:commandLink value="Yes" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" style="float:left" update="form" action="#{homeBean.stopProcess}" oncomplete="stopDialog2.hide();"/>
<p:commandButton value="NO" onclick="stopDialog2.hide()" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" style="float:right"/>
</p:dialog>
</h:form>
FacesException: DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled
this solution works to me.
Especially this answer https://stackoverflow.com/a/10527008/5250930
The table must implement the SelectableDataModel
I am trying to update the selected row (object) in <p:dataTable> when user clicks on the context menu but the object bound to <p:dataTable> selection="" doesn't updates according to row selection/context menu click, the debugging showed that the object's attributes in the bean doesn't contain any updated values but empty.
The code is:
<h:form id="searchStdentsFrm">
<p:dialog id="searchStdentsDlg" header="Search Students" widgetVar="srchStdents" modal="true">
<p:contextMenu for="srchStdentsTble" id="menuStdEdit">
<p:menuitem value="Change Status" update="stdDetail" icon="ui-icon-flag" oncomplete="PF('editStudentDialog').show()" />
<p:menuitem value="Edit Student" update="stdStatusDetail" icon="ui-icon-wrench" oncomplete="PF('editStudentStatusDialog').show()" action="#{viewStudentsBean.testAction}"/>
</p:contextMenu>
<p:dataTable id="srchStdentsTble" var="student" value="#{viewStudentsBean.studentsList}"
rowKey="#{student.id}" selection="#{viewStudentsBean.selectedStudent}"
selectionMode="single" widgetVar="srchStdentTbl"
emptyMessage="No students found with the given criteria" filteredValue="#{viewStudentsBean.filteredStudents}">
<p:ajax event="contextMenu"/>
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search Students:" />
<p:inputText id="globalFilter" onkeyup="PF('srchStdentTbl').filter()" style="width:200px" placeholder="Enter keyword"/>
</p:outputPanel>
</f:facet>
<p:column id="stdentId" headerText="Id" filterBy="#{student.id}" filterStyle="display:none">
<h:outputText value="#{student.id}" />
</p:column>
<p:column id="stdentFirstName" headerText="Firstname" filterBy="#{student.firstName}" filterStyle="display:none">
<h:outputText value="#{student.firstName}" />
</p:column>
<p:column id="stdentLastname" headerText="Lastname" filterBy="#{student.lastName}" filterStyle="display:none">
<h:outputText value="#{student.lastName}" />
</p:column>
<p:column id="stdentFathername" headerText="Father name" filterBy="#{student.fatherName}" filterStyle="display:none">
<h:outputText value="#{student.fatherName}" />
</p:column>
<p:column id="stdentGender" headerText="Gender" filterBy="#{student.gender}" filterStyle="display:none">
<h:outputText value="#{student.gender}" />
</p:column>
<p:column id="stdentDOB" headerText="Date Of birth" filterBy="#{student.dob}" filterStyle="display:none">
<h:outputText value="#{student.dob}" />
</p:column>
<p:column id="stdentSkype" headerText="Skype/Email" filterBy="#{student.skypeOrEmailId}" filterStyle="display:none">
<h:outputText value="#{student.skypeOrEmailId}" />
</p:column>
<p:column id="stdentPhone" headerText="Phone No" filterBy="#{student.phoneNumber}" filterStyle="display:none">
<h:outputText value="#{student.phoneNumber}" />
</p:column>
<p:column id="stdentAddrs" headerText="Address" filterBy="#{student.address}" filterStyle="display:none">
<h:outputText value="#{student.address}" />
</p:column>
<p:column id="stdentCountry" headerText="Country" filterBy="#{student.country}" filterStyle="display:none">
<h:outputText value="#{student.country}" />
</p:column>
<p:column id="stdentJOD" headerText="Joining Date" filterBy="#{student.dateOfJoining}" filterStyle="display:none">
<h:outputText value="#{student.dateOfJoining}" />
</p:column>
<p:column id="stdentGenralRmrks" headerText="General Remarks" filterBy="#{student.generalRemarks}" filterStyle="display:none">
<h:outputText value="#{student.generalRemarks}" />
</p:column>
<p:column id="studentStatus" headerText="Student Status" filterBy="#{student.studentStatus}" filterStyle="display:none">
<h:outputText value="#{student.studentStatus}" />
</p:column>
</p:dataTable>
</p:dialog>
<p:dialog id="editStdentDlg" header="Edit Student" widgetVar="editStudentDialog" modal="true">
<p:outputPanel id="stdDetail" style="text-align:center;">
<p:outputLabel value="First Name *" />
<p:inputText value="#{viewStudentsBean.selectedStudent.lastName}"/>
<p:panelGrid id="editStdPanelGrd" columns="2" cellpadding="5" style="width: 100%;">
<p:outputLabel value="First Name *" />
<p:inputText id="stdEditFname" value="#{viewStudentsBean.selectedStudent.firstName}"/>
<p:outputLabel value="Last Name *" />
<p:inputText id="stdEditLastname" value="#{viewStudentsBean.selectedStudent.lastName}"/>
<p:outputLabel value="Father's Name *" />
<p:inputText id="stdEditFathName" value="#{viewStudentsBean.selectedStudent.fatherName}"/>
<p:outputLabel value="Gender *" />
<h:selectOneMenu id="stdEditGnder" value="#{viewStudentsBean.selectedStudent.gender}">
<f:selectItem itemValue="Male" itemLabel="Male" />
<f:selectItem itemValue="Female" itemLabel="Female" />
</h:selectOneMenu>
<p:outputLabel value="Date Of Birth *" />
<p:calendar id="stdEditDOB" value="#{viewStudentsBean.selectedStudent.dob}"/>
<p:outputLabel value="Skype Id/Email *" />
<p:inputText id="stdEditSkype" value="#{viewStudentsBean.selectedStudent.skypeOrEmailId}"/>
<p:outputLabel value="Phone No *" />
<p:inputText id="stdEditPNo" value="#{viewStudentsBean.selectedStudent.phoneNumber}"/>
<p:outputLabel value="Address *" />
<p:inputText id="stdEditAddrs" value="#{viewStudentsBean.selectedStudent.address}"/>
<p:outputLabel value="Country *" />
<p:inputText id="stdEditCountry" value="#{viewStudentsBean.selectedStudent.country}"/>
<p:outputLabel value="Date of joining *" />
<p:calendar id="stdEditDOJ" value="#{viewStudentsBean.selectedStudent.dateOfJoining}"/>
<p:outputLabel value="General Remarks" />
<p:inputText id="stdEditGR" value="#{viewStudentsBean.selectedStudent.generalRemarks}"/>
</p:panelGrid>
</p:outputPanel>
</p:dialog>
<p:dialog id="editStdentStatusDlg" header="Edit Student" widgetVar="editStudentStatusDialog" modal="true">
<p:outputPanel id="stdStatusDetail" style="text-align:center;">
The current status of:<p:outputLabel value="#{viewStudentsBean.selectedStudent.lastName}"/>
is: <p:outputLabel value="#{viewStudentsBean.selectedStudent.studentStatus}" />
</p:outputPanel>
</p:dialog>
</h:form>
PS: I am using JSF 2.2 with PrimeFaces 5.0
I am absolutely stuck here. Any help would be greatly appreciated
Found the solution. Actually the second dialog in which i wanted to display/edit the selection object binded to p:datatable, required to be updated in context menu like:
update=":searchStdentsForm:editStdentDlg"
means the form and dialog needed to be explicitly referred.
I have recently started to maintain an online system. It is using JSF with PrimeFaces for the front end, with a Java backend. JSF is a new technology for me.
When I execute the app, and click on the buttons, absolutely nothing happens. There are no errors in the execution. It simply doesn't do a thing.
Any ideas?
xHTML file:
<p:form>
<p:dialog header="Détail demande" widgetVar="demandeDialog"
resizable="false" id="demDlg" showEffect="fade" hideEffect="explode"
width="800px" closable="true" appendToBody="true" maximizable="true"
minimizable="true">
<h:commandButton value="Imprimer" type="button" icon="ui-icon-print"
styleClass="alignmentRight">
<p:printer target="displayDem" />
</h:commandButton>
<p:accordionPanel id="displayDem" multiple="true">
<p:tab title="Informations générales">
<h:panelGrid id="displayInfoGen" columns="4" cellpadding="10">
<h:outputText value="N° demande" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.idDemande}" />
<h:outputText value="N° de devis" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.lastDevis.numDevis}" />
<h:outputText value="Date de saisie de la demande"
style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.dateSaisie}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
<h:outputText value="Date de réception de la demande"
style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.dateDemande}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
<h:outputText value="Observations" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.observations}" />
</h:panelGrid>
</p:tab>
<p:tab title="Programmes">
<h:panelGrid columns="4" cellpadding="10">
<h:outputText value="Programme" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.idProgramme.codeProgImmobilier} - #{demandeController.selectedDemande.idProgramme.nomCommercial}" />
<h:outputText value="N° de lot" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.idBien.idBien}" />
<h:outputText value="Nom de l'acquéreur" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.idAcquereur.genreEtatCivil} #{demandeController.selectedDemande.idAcquereur.prenomAcquereur} #{demandeController.selectedDemande.idAcquereur.nomAcquereur}" />
</h:panelGrid>
</p:tab>
<p:tab title="Pièces jointes">
<h:panelGrid columns="4" cellpadding="10">
<h:outputText value="Fiche de demande de TMA"
style="font-weight:bold" />
<h:commandLink action="#{demandeController.displayPj}"
value="#{demandeController.ficheDemandeTma.nom}">
<f:setPropertyActionListener
value="#{demandeController.ficheDemandeTma}"
target="#{demandeController.ficheToDisplay}" />
</h:commandLink>
<h:outputText value="Fiche d'aide à la vente"
style="font-weight:bold" />
<h:commandLink action="#{demandeController.displayPj}"
value="#{demandeController.ficheAideVente.nom}">
<f:setPropertyActionListener
value="#{demandeController.ficheAideVente}"
target="#{demandeController.ficheToDisplay}" />
</h:commandLink>
<h:outputText value="Plans" style="font-weight:bold" />
<h:commandLink action="#{demandeController.displayPj}"
value="#{demandeController.plan.nom}">
<f:setPropertyActionListener value="#{demandeController.plan}"
target="#{demandeController.ficheToDisplay}" />
</h:commandLink>
<h:outputText value="Chèque d'ouverture de dossier reçu"
style="font-weight:bold" />
<h:outputText value="#{demandeController.chequeOuverture}" />
</h:panelGrid>
</p:tab>
<p:tab title="Devis">
<h:panelGrid columns="4" cellpadding="10">
<h:outputText value="Date de validité du devis"
style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.lastDevis.datValidite}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
<h:outputText value="Date du plan de référence"
style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.lastDevis.datPlanReference}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
<h:outputText value="Frais de dossier" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.lastDevis.fraDossiers}" />
<h:outputText value="Frais de pilotage" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.lastDevis.fraPilotage}" />
<h:outputText value="Frais de plan" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.lastDevis.fraPlan}" />
<h:outputText value="Fiche option" style="font-weight:bold" />
<h:outputText
value="#{demandeController.selectedDemande.lastDevis.ficOption}" />
</h:panelGrid>
</p:tab>
<p:tab title="Lignes de chiffrages">
<h:panelGrid columns="1" cellpadding="10">
<p:dataTable var="ligne"
value="#{demandeController.selectedDemande.lastDevis.lignes}"
scrollable="true" scrollHeight="100"
emptyMessage="Pas de lignes" id="listLignes">
<p:column headerText="Lot" style="width: 10%"
sortBy="#{ligne.idLot.libelle}" rowspan="2">
<h:outputText value="#{ligne.idLot.libelle}" />
</p:column>
<p:column headerText="Descriptif" style="width: 27%"
sortBy="#{ligne.libelleDescriptif}" rowspan="2">
<h:outputText value="#{ligne.libelleDescriptif}" />
</p:column>
<p:column headerText="Charge" style="width: 12%"
sortBy="#{ligne.charge}" rowspan="2">
<h:outputText value="#{ligne.charge}" />
</p:column>
<p:column headerText="Qte" style="width: 8%"
sortBy="#{ligne.quantite}" rowspan="2">
<h:outputText value="#{ligne.quantite}" />
</p:column>
<p:column headerText="M. unit" style="width: 9%"
sortBy="#{ligne.montantUnitaire}" rowspan="2">
<h:outputText value="#{ligne.montantUnitaire}" />
</p:column>
<p:column headerText="M. total" style="width: 10%"
sortBy="#{ligne.montantTotal}" rowspan="2">
<h:outputText value="#{ligne.montantTotal}" />
</p:column>
<p:column headerText="Possibilité" style="width: 23%"
sortBy="#{ligne.possibilite}" rowspan="2">
<h:outputText value="#{ligne.possibilite}" />
</p:column>
</p:dataTable>
<h:panelGrid id="charges" columns="4" cellpadding="10"
style="text-align: center;margin-left: 25%;width: 50%; margin-right: 25%; margin-top: 30px; background-color:RGB(225,240,233)">
<h:outputText id="chargeSncHt" value="Charge SNC HT"
style="font-weight:bold" />
<h:outputText for="chargeSncHt"
value="#{demandeController.chargeSncHt}">
<f:convertNumber maxFractionDigits="2" />
</h:outputText>
<h:outputText id="chargeAcqHt" value="Charge Acq HT"
style="font-weight:bold" />
<h:outputText for="chargeAcqHt"
value="#{demandeController.chargeAcqHt}">
<f:convertNumber maxFractionDigits="2" />
</h:outputText>
<h:outputText id="chargeSncTtc" value="Charge SNC TTC"
style="font-weight:bold" />
<h:outputText for="chargeSncTtc"
value="#{demandeController.chargeSncTtc}">
<f:convertNumber maxFractionDigits="2" />
</h:outputText>
<h:outputText id="chargeAcqTtc" value="Charge ACQ TTC"
style="font-weight:bold" />
<h:outputText for="chargeAcqTtc"
value="#{demandeController.chargeAcqTtc}">
<f:convertNumber maxFractionDigits="2" />
</h:outputText>
</h:panelGrid>
</h:panelGrid>
</p:tab>
<p:tab title="Documents">
<h:panelGrid columns="5" cellpadding="2" width="100%"
style="text-align: center">
<h:commandButton title="Générer le devis" id="genDevis"
actionListener="#{demandeController.genererDevis}" immediate="true"
image="/resources/images/pdf.png"
style="vertical-align: middle">
Devis convention.pdf
</h:commandButton>
<p:commandButton title="Plans scannés" id="addPlansScannes"
style="vertical-align: middle; width: 130px;"
onclick="lazyload()" ajax="true" icon="ui-icon-search"
value="Plans scannés">
<f:ajax event="click"
listener="#{demandeController.onPlansClicked}" />
</p:commandButton>
<h:commandButton title="Générer le courrier" id="genCourrier"
action="#{demandeController.genererCourrier}" immediate="true"
image="/resources/images/pdf.png"
style="vertical-align: middle">
Courrier pour les acquereurs.pdf
</h:commandButton>
<h:commandButton title="Générer la fiche suiveuse"
id="genFicheSuiveuse" action="#{ficheSuiveuseController.init}"
immediate="true"
image="/resources/images/excel.png"
style="vertical-align: middle">
Fiche suiveuse.xls
<f:setPropertyActionListener
value="#{demandeController.selectedDemande}"
target="#{ficheSuiveuseController.selectedDemande}" />
</h:commandButton>
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="10" width="100%"
style="text-align: center" id="lazypanel">
<p:dataTable id="plansDT" var="plan"
value="#{demandeController.listPlansScannes}"
rendered="#{demandeController.plansClicked}"
emptyMessage="Pas de Plan">
<p:column headerText="Plans" style="width: 100%"
sortBy="#{plan.nom}">
<h:commandLink action="#{demandeController.displayFiles}"
value="#{plan.nom}">
<f:setPropertyActionListener value="#{plan}"
target="#{demandeController.ficheToDisplay}" />
</h:commandLink>
</p:column>
</p:dataTable>
</h:panelGrid>
<p:remoteCommand name="lazyload" update="lazypanel"
actionListener="#{demandeController.onPlansClicked()}">
</p:remoteCommand>
</p:tab>
</p:accordionPanel>
</p:dialog>
</p:form>
EDIT
When I inspect the element I get this:
<input id="detailsDemandesForm:displayDem:genDevis" type="image" title="Générer le devis" style="vertical-align: middle" name="detailsDemandesForm:displayDem:genDevis" src="/workflowtma-presentation-war/resources/images/pdf.png"></input>
Devis convent…
From a quick glance your issue might be caused by No. 1 of the list of such problems.
In particular your use of appendToBody="true" makes me suspect that Primefaces is moving your dialog out of the <p:form> you declared it in. Try moving the form inside the dialog like so:
<p:dialog ...>
<p:form>
<!-- content goes here -->
</p:form>
</p:dialog>