simple primefaces dialog does not affect value to property - jsf

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"

Related

Update data table in dialog from another dialog in PrimeFaces 5

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>

datatable selection is not updated when open dialog

i have an issue. I have one form and a dialog with another form inside. The second form has a datatable with radiobutton selection. When i open the dialog by first time, the selection is shown fine. I close the dialog. But when i try with another element, the selection on the datatable don't be updated.
The configuration that i use is:
Mojarra 2.2.4
Primefaces 4.0
But, if i use the Primefaces 3.5 version, it works.
I attach the xhtml files.
First file
<h:form id="formPlanificarCursos">
<p:outputPanel styleClass="pnlDeclaracionMessages">
<p:messages showSummary="true" />
</p:outputPanel>
<p:panel id="pnlPlanHorarioCurso" styleClass="pnlPlanHorarioCurso non-borders">
<components:titleSeparator title="Horarios de Curso" />
<!-- Toolbar -->
<p:outputPanel layout="block" styleClass="toolbar">
<p:commandLink id="btnAgregar" update="#(.dlgHorarioCurso)"
oncomplete="jQuery('.dlgHorarioCurso .ui-dialog-title').text('#{plan_msgs['planCurso.registrar.titulo']}'); dlgHorarioCurso.show();">
<h:graphicImage value="/resources/images/document_add.png" />
</p:commandLink>
<p:tooltip for="btnAgregar" value="Agregar Horario" />
</p:outputPanel>
<p:schedule id="scheduleCurso" minTime="6" value="#{detallePlanCursoBean.scheduleModel}" styleClass="scheduleCurso schedule-without-days"
allDaySlot="false" showHeader="false" view="agendaWeek" axisFormat="HH:mm" timeFormat="H:mm{ - H:mm}" aspectRatio="4" locale="es"
widgetVar="scheduleCurso">
<p:ajax event="eventSelect" listener="#{detallePlanCursoBean.onEventSelect}" update="#(.dlgHorarioCurso)"
oncomplete="jQuery('.dlgHorarioCurso .ui-dialog-title').text('#{plan_msgs['horarioCurso.modificar.titulo']}'); dlgHorarioCurso.show();" />
</p:schedule>
<f:facet name="footer">
<div class="div-botonera">
<p:commandButton id="btnAceptar" value="Aceptar" action="#{detallePlanCursoBean.registrarDetallePlanCurso}" />
<p:commandButton id="btnCancelar" value="Cancelar" action="#{detallePlanCursoBean.irConsultarPlanCurso}" immediate="true" />
</div>
</f:facet>
</p:panel>
</h:form>
<!-- Agregar Disponibilidad Horaria -->
<p:dialog widgetVar="dlgHorarioCurso" styleClass="dlgHorarioCurso" modal="true" resizable="false" closable="false">
<p:ajax event="close" listener="#{detallePlanCursoBean.cancelarHorarioCurso}" />
<ui:include src="/planificacion/horarioCurso.xhtml" />
</p:dialog>
Second file
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:components="http://java.sun.com/jsf/composite/components">
<h:form id="frmHorarioCurso">
<p:panel styleClass="pnlHorarioCurso non-borders">
<p:messages id="messagesfrmHorarioCurso" />
<components:titleSeparator title="Aula" />
<p:outputPanel id="pnlAulas" styleClass="pnlAulas" style="border-width:0px;">
<p:dataTable emptyMessage="No hay aulas para seleccionar." var="aula" id="grdAulas" styleClass="grdAulas"
value="#{detallePlanCursoBean.aulaModel}" selection="#{detallePlanCursoBean.detallePlanCursoDTO.aula}" rows="3" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false" widgetVar="grdAulas">
<p:column selectionMode="single" style="width:15px;" />
<p:column headerText="Nombre">
<h:outputText value="#{aula.nombre}" />
</p:column>
<p:column headerText="UbicaciĆ³n">
<h:outputText value="#{aula.locacion.nombre}" />
</p:column>
<p:column headerText="Capacidad" style="text-align:center;width:100px;">
<h:outputText value="#{aula.capacidad}" />
</p:column>
<p:column headerText="Accesibilidad" style="width:10%; text-align:center;">
<p:selectBooleanCheckbox value="#{aula.accesible}" disabled="true" />
</p:column>
</p:dataTable>
</p:outputPanel>
<f:facet name="footer">
<div class="div-botonera">
<p:commandButton value="Aceptar" action="#{detallePlanCursoBean.agregarHorarioCurso}" update="#(.pnlHorarioCurso)"
oncomplete="if(!args.validationFailed) HorarioCurso.handleComplete(xhr, status, args);" />
<p:commandButton value="Cancelar" oncomplete="scheduleCurso.update(); dlgHorarioCurso.hide();" update="#(.pnlHorarioCurso)" immediate="true"
action="#{detallePlanCursoBean.cancelarHorarioCurso}" />
</div>
</f:facet>
</p:panel>
</h:form>
I appreciate your help.
I was having a problem similar to this. I had a dialog which was being opened with information based on a pre-selected dataTable row, but the content of this dialog was not being updated after the first time it was opened.
I solved my problem by adding the attribute "process=#form" to my commandLink and in your case i think the update attribute should be update=":dlgHorarioCurso"

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>

clear dialog box JSF

I tried many things but it's not working, i have a Wizard into a dialog box and when i submit the form and reopen the dialog i found it in the last statues with the last data this is my code :
<p:wizard id="wizForNewIssue" widgetVar="wizNewIsssue"
flowListener="#{managedBeanProjects.onFlowProcess}"
style="width:100%;">
<p:tab id="personal" title="Details">
<p:panel style="width:800px;height:200px">
<h:messages errorClass="error" />
<h:panelGrid id="new0" columns="3">
...........
</h:panelGrid>
<f:facet name="footer">
<h:outputText value="Skip to last: " />
<h:selectBooleanCheckbox value="#{managedBeanProjects.skip}" />
</f:facet>
</p:panel>
</p:tab>
<p:tab id="version" title="Version Details">
<p:panel style="width:800px;height:200px">
............
</p:panel>
</p:tab>
<p:tab id="goConfirm" title="Confirmation">
<p:panel style="width:800px;height:200px">
<h:panelGrid id="final" columns="4">
.............
</h:panelGrid>
<f:facet name="footer">
<p:commandButton value="Submit"
update=":form1:growl :form1:dialogNewIssue "
actionListener="#{managedBeanProjects.newIssue}"
oncomplete="newDialog.hide()" />
</f:facet>
</p:panel>
</p:tab>
</p:wizard>
</p:dialog>
Primefaces wizard has "step" attribute to set "Id of the current step in flow", you can set Id of tab you want to show:
<p:wizard step="#{managedBeanProjects.tabIndex}" id="wizForNewIssue" widgetVar="wizNewIsssue"
flowListener="#{managedBeanProjects.onFlowProcess}"
style="width:100%;">
bean:
if(true){
tabIndex = "personal";
}

commandbutton in dataList inside tab of accordionPanel is it posible primefaces jsf

I cant make work the commandbutton, all data is displayed corectly and the dialogbox is showing but the selectedcontacto is not changing.
<p:tab title="#{grup.nombre}">
<p:dataList value="#{grup.listausuarios}" var="cont"
paginator="true" rows="5"
paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15" type="none">
<p:commandButton icon="ui-icon-search" update=":frmindex:carDetail" onsuccess="carDialog.show()" title="View Detail">
<f:setPropertyActionListener value="#{cont.idusuario}" target="#{bnContactos.selectedcontacto}" />
</p:commandButton>
<h:panelGrid columns="2">
<p:graphicImage value="/resources/user.png" width="60" height="100"/>
<h:panelGrid columns="2">
<h:outputText value="Nombre: " />
<h:outputText value="#{cont.nombre}" style="font-weight: bold"/>
<h:outputText value="Correo: " />
<h:outputText value="#{cont.correo}" style="font-weight: bold"/>
</h:panelGrid>
</h:panelGrid>
</p:dataList>
</p:tab>
</p:accordionPanel>
EDIT:Finally i found how make it work if someone cares here my new code.(p:column plus process="#this" made the button works why? i dont know i just take something here something of there and result is as following)
<p:accordionPanel id="tcon" value="#{bnContactos.listagruposmodel}" dynamic="true" var="grup" >
<p:tab title="#{grup.nombre}">
<p:dataList value="#{grup.listausuarios}" var="cont" id="dtus"
paginator="true" rows="5"
paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15" lazy="true" >
<p:column>
<h:panelGrid columns="2">
<p:graphicImage value="/resources/user.png" width="60" height="100"/>
<h:panelGrid columns="2">
<h:outputText value="Nombre: " />
<h:outputText value="#{cont.nombre}" style="font-weight: bold"/>
<h:outputText value="Correo: " />
<h:outputText value="#{cont.correo}" style="font-weight: bold"/>
<p:commandButton process="#this" ajax="true" icon="ui-icon-search" update=":frmindex:messages" action="#{bnContactos.borrar(cont.idusuario)}" title="View Detail"/>
</h:panelGrid>
</h:panelGrid>
</p:column>
</p:dataList>
</p:tab>
</p:accordionPanel>

Resources