Update data table in dialog from another dialog in PrimeFaces 5 - jsf

I am new to JSF/PrimeFaces and am trying to update a DataTable(SearchResultsTable) in my Dialog(SearchResultsDlg)from another Dialog(SearchDlg) I tried putting my List of Objects on the the FacesContext and I tried to make it the return type but Dialog(SearchResultsDlg) keeps popping up empty. No errors on the java side and I know I'm returning a List of type Object from my query. Here is snippits of code in the order in which they execute. Any ideas would be great!
Search.xhtml
<ui:composition>
<p:dialog id="SearchDlg"
widgetVar="SearchDialog"
modal="true"
resizable="false"
appendTo="#(body)" header="#{bundle.Search}">
<h:form id="SearchForm" >
<h:panelGroup id="SearchDisplay">
<p:panelGrid columns="2">
<p:outputLabel id="SearchLabel" value="What" />
<p:inputText id="SearchText" value="#{offerController.searchText}" size="40"/>
<p:outputLabel id="ZipCodeLabel" value="Where" />
<p:inputText id="postalcode" value="#{offerController.postalCode}" size="12"/>
</p:panelGrid>
<p:commandButton id="Search"
value="Search"
actionListener="#{offerController.search}"
onclick="handleSubmit(args, 'SearchDialog')" />
<p:commandButton value="#{bundle.Cancel}" onclick="SearchDialog.hide()"/>
</h:panelGroup>
</h:form>
</p:dialog>
</ui:composition>
OfferController.java
public List<Offer> search() {
List<Offer> offers = null;
try {
offers = getFacade().search(PostalCode, Distance, Category, SubCategory, SearchText, SearchType);
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("offer", offers);
RequestContext.getCurrentInstance().openDialog("SearchResult");
RequestContext.getCurrentInstance().update("SearchResultsTable");
} catch (Exception e) {
System.out.println(e);
}
return offers;
}
SearchResults.xhtml
<ui:composition>
<p:dialog id="SearchResultsDlg"
widgetVar="SearchResultsDialog"
modal="true"
resizable="false"
appendTo="#(body)"
header="#{bundle.Login}" >
<ui:define name="title">
<h:outputText value="#{bundle.ListOfferTitle}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:form id="SearchResultsForm">
<p:panel header="#{bundle.ListOfferTitle}">
<p:dataTable id="SearchResultsTable" value="#{offerController.search}" var="offer"
selectionMode="single" selection="#{offerController.selected}"
paginator="true"
rowKey="#{offer.name}"
rows="10"
rowsPerPageTemplate="10,20,30,40,50">
<p:ajax event="rowSelect" update="createButton viewButton editButton deleteButton"/>
<p:ajax event="rowUnselect" update="createButton viewButton editButton deleteButton"/>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfferTitle_sellerUserID}"/>
</f:facet>
<h:outputText value="#{offer.sellerUserID}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfferTitle_name}"/>
</f:facet>
<h:outputText value="#{offer.name}"/>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
</ui:define>
</p:dialog>
</ui:composition>

Use selector for update:
p:dataTable id="SearchResultsTable" styleClass="for-update"
and button or ajax:
p:commandButton id="Search" update="#(.for-update)"

You have to reference the component you want to update from the component that tirggers the update action. For example if I want to update "dataTable1" contained in "dialog1" from "button2" contained in "dialog2":
<p:dialog id="dialog1" ... >
<h:form id="form1">
<p:dataTable id="dataTable1"...>
...
</p:dataTable>
</h:form>
</p:dialog>
<p:dialog id="dialog2" ... >
<h:form id="form2">
<p:commandButton
process="#form" update=":form1:dataTable1" />
</h:form>
</p:dialog>

Related

Calling two dialog and save in two methods in JSF

I have two buttons and two dialog, each button calls a dialog, each dialog has a save button, you send two different methods in the Bean. The problem is that it only works sending a dialog and not the other.
xhtml
<h:form id='form1'>
<p:panel id="basic" header="#{usuarioBean.nompagina}" footer="" style="margin-bottom:20px">
<p:panelGrid columns="3" style="width: 100%">
<p:commandButton value="Nuevo" icon="ui-icon-document" actionListener="#{menuBean.setAccion('Registrar')}" type="button" onclick="PF('dlg').show();" update=":dialog"/>
</p:panelGrid>
.......
<p:column headerText="Acción">
<p:commandButton value="Asignar Rol" actionListener="#{usuarioBean.leerUsuario(rowusu)}" oncomplete="PF('wdatosvar').show()" update=":wdatosid" icon="ui-icon-person"/>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
<p:dialog position="center top" styleClass="ui-widget-container" id="dialog" header="Usuarios" widgetVar="dlg" dynamic="true" modal="true" width="400">
<h:form>
<p:panelGrid columns="2">
...
<p:commandButton value="Guardar" actionListener="#{usuarioBean.inUsuario()}" oncomplete="handleDialogSubmit2(args)" update=":form1:listusuario" icon="ui-icon-check" />
<p:commandButton value="Cancelar" immediate="true" onclick="PF('dlg').hide();" icon="ui-icon-cancel" />
<p:outputLabel id="refresc" />
</p:panelGrid>
</h:form>
</p:dialog>
<p:dialog header="Datos" position="center top" widgetVar="wdatosvar" id="wdatosid" modal="true" showEffect="explode" hideEffect="explode">
<h:form>
<h:panelGrid columns="2">
...
<p:commandButton value="Guardar" actionListener="#{usuarioBean.saveUsuario()}" oncomplete="handleDialogSubmit(xhr, status, args)" update=":form1:listusuario,#form,refrescar" icon="ui-icon-check" />
<p:commandButton value="Cancelar" immediate="true" onclick="PF('wdatosvar').hide();" icon="ui-icon-cancel" />
<p:outputLabel id="refrescar" />
</h:panelGrid>
</h:form>
</p:dialog>
And usuarioBean.java
#ManagedBean
#SessionScoped
public class usuarioBean {
public void saveUsuario() throws Exception {
usuariohistorialDAO dao = new usuariohistorialDAO();
try {
dao.insertCredencial(usuariohis,value1);
this.listarUsuarios(palabra);
} catch (Exception e) {
throw e;
}
}
public void inUsuario() throws Exception{
usuariohistorialDAO dao = new usuariohistorialDAO();
try {
dao.insertarUsuario(usuariohis);
this.listarUsuarios(palabra);
} catch (Exception e) {
throw e;
}
}
}
inUsuario does no work.
Do not know exactly why but this form solves my problem
<h:form id='form1'>
<p:panel id="basic" header="Lista de Usuarios" footer="" style="margin-bottom:20px">
<p:panelGrid columns="3" style="width: 100%">
<p:commandButton value="Nuevo" icon="ui-icon-document" oncomplete="PF('dlg').show()" update=":dialog"/>
</p:panelGrid>
<p:inputText value="#{usuarioBean.palabra}" id="search" class="inputmediano"/>
<p:commandButton value="Buscar" icon="ui-icon-refresh" actionListener="#{usuarioBean.bucarUsuario()}" update="listusuario"/>
<p:dataTable tableStyleClass="ui-table-columntoggle" var="rowusu" value="#{usuarioBean.arrayusu}" paginator="true" paginatorPosition="bottom" rows="30" id="listusuario" style="width: 100%;margin-top: 10px" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
<p:column headerText="Id" style="width: 25px">
<h:outputText value="#{rowusu.ush_id}"/>
</p:column>
<p:column headerText="Usuario" >
<h:outputText value="#{rowusu.usu_nombre}"/>
</p:column>
<p:column headerText="Sexo" >
<h:outputText value="#{rowusu.usu_sexo}"/>
</p:column>
<p:column headerText="Nick">
<h:outputText value="#{rowusu.ush_correo}" />
</p:column>
<p:column headerText="Rol">
<h:outputText value="#{rowusu.nomrol}"/>
</p:column>
<p:column headerText="Cargo">
<h:outputText value="#{rowusu.nomcargo}"/>
</p:column>
<p:column headerText="Acción">
<p:commandButton value="Asignar Rol" actionListener="#{usuarioBean.leerUsuario(rowusu)}" oncomplete="PF('wdatosvar').show()" update=":wdatosid" icon="ui-icon-person"/>
<p:commandButton value="Modificar" actionListener="#{usuarioBean.leerUsuario(rowusu)}" oncomplete="PF('dlg').show()" update=":dialog" icon="ui-icon-person"/>
</p:column>
</p:dataTable>
</p:panel>
</h:form>

simple primefaces dialog does not affect value to property

I have a simple input text inside a primefaces dialog with a command button to test if the variable gets his value but when i click the command button with(process="#this" when i delete it the button dont work any more)to print the value of the property it shows always null ... the dialog is rented by a command link from a data grid and when i delete the dialog every thing works fine and the property get th value this is the jsf page :
<p:layoutUnit id="center" position="center"
style="min-height:400px;min-width:300px;overflow-y:hidden !important"
header="#{messages['layout.center.header']}">
<f:view>
<h:form >
<p:dataGrid var="c" value="#{rentMB.carsList}" columns="3"
layout="grid" rows="12" paginator="true" id="cars"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="6,12,16">
<f:facet name="header">
Available Cars
</f:facet>
<p:panel header="#{c.car_brand.brand_name}"
style="text-align:center">
<h:panelGrid columns="1" style="width:100%">
<p:graphicImage url="/images/#{c.image}.jpg" />
<p:commandLink
oncomplete="PF('carDialog').show()" title="View Detail">
<h:outputText styleClass="ui-icon ui-icon-key"
style="margin:0 auto;" />
<f:setPropertyActionListener value="#{c}"
target="#{rentMB.selectedCar}" />
</p:commandLink>
</h:panelGrid>
</p:panel>
</p:dataGrid>
</h:form>
<h:form>
<p:dialog header="Car Info" id="carInfo" widgetVar="carDialog" width="900px"
height="400px" showEffect="fade" hideEffect="fade"
resizable="false" appendToBody="true">
<p:outputPanel>
<h:panelGrid columns="3" >
<f:facet name="header">
Client informations
</f:facet>
<h:outputLabel for="adress" value="Adress : *" />
<p:inputText id="adress" value="#{rentMB.adress}"
/>
<p:watermark for="adress" value="Adress" />
<p:commandButton action="#{rentMB.affiche}" process="#this" value="Rent" oncomplete="carInfo.hide();" > </p:commandButton>
<p:commandButton type="reset" value="Reset"> </p:commandButton>
</h:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</f:view>
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>
the code of rentMB.affiche() :
public void affiche()
{
System.out.println(this.getAdress());
}
the solution is to put the content of the p:dialog between <h:form></h:form> and add to dialog appendToBody="false"

Primefaces update strange behaviour

i have a strange behaviour on Primefaces update :
I have i page with a panel grid with several output text and a dataTable with several rows. If I modify a row, the datatable update correctly, but if I insert a new row or delete a row it doesn't update. The page code is the following:
<ui:composition>
<p:dialog id="composizioneDlg" widgetVar="ComposizioneDialog" modal="true" resizable="false" appendTo="#(body)" header="#{bundle.ListDescImmTitle}">
<h:form id="composizioneListForm">
<p:panelGrid columns="10" rendered="#{immobiliController.selected != null}">
<h:outputText value="#{bundle.ViewImmobiliLabel_categoria}"/>
<h:outputText value="#{immobiliController.selected.categoria.descrizione}"
-------SEVERAL OUTPUTS---------------------------------
</p:panelGrid>
<p:panel header="#{bundle.ListDescImmTitle}">
<p:dataTable id="datalistComp" value="#{descImmController.composizione}" var="item" >
-----SEVERAL OPTIONS OF DATA TABLE-------------------
<p:ajax event="rowSelect" update="createButton viewButton editButton deleteButton"/>
<p:ajax event="rowUnselect" update="createButton viewButton editButton deleteButton"/>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDescImmTitle_stato}"/>
</f:facet>
<h:outputText value="#{item.stato}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDescImmTitle_categoria}"/>
</f:facet>
<h:outputText value="#{item.categoria}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDescImmTitle_descrizione}"/>
</f:facet>
<h:outputText value="#{item.descrizione}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDescImmTitle_mq}"/>
</f:facet>
<h:outputText value="#{item.mq}"/>
</p:column>
<f:facet name="footer">
<p:commandButton id="createButton" icon="ui-icon-plus" value="#{bundle.Create}" actionListener="#{descImmController.prepareCreate}" update=":DescImmCreateForm" oncomplete="PF('DescImmCreateDialog').show()"/>
<p:commandButton id="editButton" icon="ui-icon-pencil" value="#{bundle.Edit}" update=":DescImmEditForm" oncomplete="PF('DescImmEditDialog').show()" disabled="#{empty descImmController.selected}"/>
<p:commandButton id="deleteButton" icon="ui-icon-trash" value="#{bundle.Delete}" actionListener="#{descImmController.destroy}" update=":composizioneListForm:datalistComp, :growl" disabled="#{empty descImmController.selected}"/>
</f:facet>
</p:dataTable>
</p:panel>
</h:form>
</p:dialog>
</ui:composition>
The editButton code is this ( and it works ):
<ui:composition>
<p:dialog id="DescImmEditDlg" widgetVar="DescImmEditDialog" modal="true" resizable="false" appendTo="#(body)" header="#{bundle.EditDescImmTitle}">
<h:form id="DescImmEditForm">
<h:panelGroup id="display">
<p:panelGrid columns="2" rendered="#{descImmController.selected != null}">
<p:outputLabel value="#{bundle.EditDescImmLabel_stato}" for="stato" />
<p:inputText id="stato" value="#{descImmController.selected.stato}" title="#{bundle.EditDescImmTitle_stato}" />
<p:outputLabel value="#{bundle.EditDescImmLabel_descrizione}" for="descrizione" />
<p:inputText id="descrizione" value="#{descImmController.selected.descrizione}" title="#{bundle.EditDescImmTitle_descrizione}" />
<p:outputLabel value="#{bundle.EditDescImmLabel_mq}" for="mq" />
<p:inputText id="mq" value="#{descImmController.selected.mq}" title="#{bundle.EditDescImmTitle_mq}" />
</p:panelGrid>
<p:commandButton actionListener="#{descImmController.update}" value="#{bundle.Save}" update="display, :composizioneListForm:datalistComp, :growl" oncomplete="handleSubmit(args, 'DescImmEditDialog');"/>
<p:commandButton value="#{bundle.Cancel}" onclick="DescImmEditDialog.hide()"/>
</h:panelGroup>
</h:form>
</p:dialog>
</ui:composition>
This is the code of createButton ( not update instead of editButton ) :
<ui:composition>
<p:dialog id="DescImmCreateDlg" widgetVar="DescImmCreateDialog" modal="true" resizable="false" appendTo="#(body)" header="#{bundle.CreateDescImmTitle}">
<h:form id="DescImmCreateForm">
<h:panelGroup id="display">
<p:panelGrid columns="2" rendered="#{descImmController.selected != null}">
<p:outputLabel value="#{bundle.CreateDescImmLabel_descrizione}" for="descrizione" />
<p:inputText id="descrizione" value="#{descImmController.selected.descrizione}" title="#{bundle.CreateDescImmTitle_descrizione}" />
<p:outputLabel value="#{bundle.CreateDescImmLabel_mq}" for="mq" />
<p:inputText id="mq" value="#{descImmController.selected.mq}" title="#{bundle.CreateDescImmTitle_mq}" />
</p:panelGrid>
<p:commandButton actionListener="#{descImmController.create}" value="#{bundle.Save}" update="display, :composizioneListForm:datalistComp, :growl" oncomplete="handleSubmit(args,'DescImmCreateDialog');"/>
<p:commandButton value="#{bundle.Cancel}" onclick="DescImmCreateDialog.hide()"/>
</h:panelGroup>
</h:form>
</p:dialog>
</ui:composition>
Where is my fault on call update="" in deleteButton and in createButton ????
After rewrite the code from the beginning ( but with the same code ) all goes well. Now It works

Primefaces 3.5 DataTable Single Selection does not work with ContextMenu

I tried to make a <p:dataTable> with <p:contextMenu> using primefaces 3.5 on Mojarra 2.2.1.
The ContextMenu Code :
<p:contextMenu for="actionnairesDT">
<p:menuitem value="View" update="displayActionnaires" icon="ui-icon-search" oncomplete="actDialog.show()"/>
<p:menuitem value="Delete" update="actionnairesDT" icon="ui-icon-close" />
</p:contextMenu>
the problem is that the dialog box is displayed empty.
I tried to show my object in the setter setSelecedActionnaire(), it displays nothing
not even null.
public void setSelectedActionnaire(Actionnaires selectedActionnaire) {
System.out.println(selectedActionnaire);
this.selectedActionnaire = selectedActionnaire;
}
<p:dataTable> and <p:dialog> code is below. thank you in advance for your help !
<p:dataTable id="actionnairesDT" paginatorPosition="bottom"
pageLinks="10" paginator="true" rows="20" value="#{actionnairesBean.actionnairesList()}" var="actionnaires"
rowKey="#{actionnaires.nomAct}" selection="#{actionnairesBean.selectedActionnaire}" selectionMode="single"
>
<p:ajax event="rowSelect" update="actionnairesDT" oncomplete="actDialog.show()" />
<p:column sortBy="#{actionnaires.actionnairesPK.codeAct}" headerText="N°">
#{actionnaires.actionnairesPK.codeAct}
</p:column>
<p:column headerText="Nom" sortBy="#{actionnaires.nomAct}">
#{actionnaires.nomAct}
</p:column>
<p:column>
#{actionnaires.quatiteAct}
</p:column>
<p:column headerText="Sicav">
#{actionnaires.actionnairesPK.codeSicav}
</p:column>
</p:dataTable>
<p:dialog header="Détail Actionnaire" widgetVar="actDialog" resizable="false"
showEffect="clip" hideEffect="fold" id="actDialog" closable="true" modal="true">
<h:panelGrid id="displayActionnaires" columns="2" cellpadding="4">
<h:outputText value="Nom Actionnaire"/>
<h:outputText value="#{actionnairesBean.selectedActionnaire.nomAct}"/>
<h:outputText value="Quantité"/>
<h:outputText value="#{actionnairesBean.selectedActionnaire.quatiteAct}"/>
<h:outputText value="Sicav"/>
<h:outputText value="#{actionnairesBean.selectedActionnaire.sicavs.libelleSicav}"/>
</h:panelGrid>
</p:dialog>
In the end, I found the solution
I add <p:ajax> to the <p:dataTable>:
<p:ajax event="contextMenu"/>

Primefaces cant fill inputText in dialog after click contextmenu

I'm using Primefaces Datatable-ContextMenu and Dialog to update a row (When after click to contextmenu it opens a dialog which contains will update object's fields in <p:inputext />).
I have tried dynamic true, initilazing object on constructor because when page is rendered selectedObject will be null in dialog and when I tried to use it gives null pointer exception so that i need other advices.
Here is ContextMenu:
<p:contextMenu for="functions" id="functionContextMenu">
<p:menuitem value="Guncelle" icon="ui-icon-" update="updateDialog" oncomplete="updateDialog.show()"/>
And my dialog is here:
<p:dialog header="Guncelle" widgetVar="updateDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold" id="updateDialog" dynamic="true">
<h:panelGroup id="display">
<h:outputText value="#{functionControllerBean.selectedFunction.functionName}" />
<h:inputText id="firstName" value="{functionControllerBean.tempSelectedFunction1.functionName}" />
</h:panelGroup>
</p:dialog>
If I dont use <p:inputText /> its ok and show what i put <h:outputText /> but when i put p:inputext inside of dialog;it doesnt show output text value and shows <p:inputText /> empty even its not.
I had used beanname.objectname.field before inside of <p:inputText /> or <h:inputText /> but there was no problem but now it's not working.
And here is my ManagedBean :
#ManagedBean
#RequestScoped
public class FunctionControllerBean implements Serializable {
private EfaFunctions willAddFunction;
private EfaFunctions selectedFunction = new EfaFunctions();
Thanks in advance
UPDATE Here is page
<h:form id="form">
<p:contextMenu for="functions" id="functionContextMenu">
<p:menuitem value="Guncelle" icon="ui-icon-" update="updateDialog" oncomplete="updateDialog.show()"/>
<p:menuitem value="Sil" update="#form" icon="ui-icon-close" actionListener="#{functionControllerBean.deleteFunction}"/>
</p:contextMenu>
<p:dataTable resizableColumns="true" id="functions" var="function" value="#{functionControllerBean.functions}" rowKey="#{function.functionId}"
selection="#{functionControllerBean.selectedFunction}" selectionMode="single">
<p:column headerText="Id">
#{function.functionId}
</p:column>
<p:column headerText="Key ">
#{function.functionKey}
</p:column>
<p:column headerText="Isim" >
#{function.functionName}
</p:column>
<p:column headerText="Tip" >
#{function.functionType}
</p:column>
<p:column headerText="Url" >
#{function.uri}
</p:column>
<p:column headerText="Olusturulma Tarihi" >
#{function.creationDate}
</p:column>
<p:column headerText="Guncelleme Tarihi" >
#{function.lastUpdateDate}
</p:column>
<p:column headerText="Olusturan Kisi" >
#{function.createdBy}
</p:column>
<p:column headerText="Guncelleyen Kisi" >
#{function.createdBy}
</p:column>
</p:dataTable>
<p:dialog header="Islem Sonucu" widgetVar="actionResult" resizable="false"
width="200" showEffect="clip" hideEffect="fold" id="actionResult"
visible="#{functionControllerBean.actionResult!=null}">
<h:outputText value="#{functionControllerBean.actionResult}"/>
</p:dialog>
<p:dialog header="Guncelle" widgetVar="updateDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold" id="updateDialog" >
<h:panelGroup id="display">
<h:outputText value="#{functionControllerBean.selectedFunction.functionName}" />
<p:inputText value="#{functionControllerBean.selectedFunction.functionName}"/>
</h:panelGroup>
</p:dialog>
</h:form>

Resources