Problem Dialog to Save Edited Data

UI Components for JSF
Post Reply
zilph
Posts: 7
Joined: 17 Jun 2011, 20:52

07 Sep 2011, 22:28

Hi.. i'm new to PrimeFaces.. i created a Datatable, with 2 Buttons that display 2 Dialogs to Show and Edit Data... but i have a problem when Editing, i implemented a save method in the BackBean, and it is called when pressing the Button.. but my problem is the Data I write or update in the InputFields in the Dialog is not posted or updated, and even when I call the EJB to update the data.. it does not receive the new values written in the InputFields.. help anyone?

Zilph.

Glassfish 3.2
JSF 2
Mojarra
PrimeFaces 3.0 .M3



<?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://java.sun.com/jsf/facelets"
xmlns:utils="http://java.sun.com/jsf/composite/utils"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">


<body>



<ui:composition template="./../WEB-INF/templates/plantillaRIDEP.xhtml">


<ui:define name="center">


<h:form id="form">

<!--
<p:commandButton value="Navegar" ajax="false" action="#{ultraBean.navegar()}" />
-->

<p:growl id="msgs" showDetail="true" />

<p:dataTable var="user" value="#{lazyBean.listarConductores()}"
rows="10" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,20,30,50"
page=""




id="pnlResult"
>


<p:column>
<f:facet name="header">
<h:outputText value="IdLicencia"/>
</f:facet>
<h:outputText value="#{user.idlicencia}"/>
</p:column>


<p:column>
<f:facet name="header">
<h:outputText value="Nombre"/>
</f:facet>
<h:outputText value="#{user.nombre}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="ApPaterno"/>
</f:facet>
<h:outputText value="#{user.paterno}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="ApMaterno"/>
</f:facet>
<h:outputText value="#{user.materno}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="curp"/>
</f:facet>
<h:outputText value="#{user.curp}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Folio"/>
</f:facet>
<h:outputText value="#{user.folio}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Ciudad"/>
</f:facet>
<h:outputText value="#{user.ciudad}"/>
</p:column>


<p:column>
<f:facet name="header">
<h:outputText value="Telefono"/>
</f:facet>
<h:outputText value="#{user.telefono}"/>
</p:column>


<p:column style="width:100px">
<h:panelGrid columns="3" styleClass="actions" cellpadding="2">
<p:commandButton update=":forma2:display" oncomplete="forma2:carDialog.show()" image="ui-icon ui-icon-search" title="View">
<f:setPropertyActionListener value="#{user}" target="#{lazyBean.selectedPersona}" />
<f:setPropertyActionListener value="#{false}" target="#{lazyBean.editMode}" />
</p:commandButton>
<p:commandButton update=":forma2:display" oncomplete="forma2:carDialog.show()" image="ui-icon ui-icon-pencil" title="Edit">
<f:setPropertyActionListener value="#{user}" target="#{lazyBean.selectedPersona}" />
<f:setPropertyActionListener value="#{true}" target="#{lazyBean.editMode}" />
</p:commandButton>
<p:commandButton update=":forma2:display" oncomplete="forma2:confirmation.show()" image="ui-icon ui-icon-close" title="Delete">
<f:setPropertyActionListener value="#{user}" target="#{lazyBean.selectedPersona}" />
</p:commandButton>
</h:panelGrid>
</p:column>


</p:dataTable>

</h:form>


<h:form id="forma2">

<p:dialog header="Persona DEtallazo" closable="true" widgetVar="carDialog" appendToBody="true" resizable="false" id="carDlg"
showEffect="fade" hideEffect="explode" modal="true">

<h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">



<h:outputText value="Folio:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.folio}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.folio}" rendered="#{lazyBean.editMode}" required="true" label="Model"/>
</h:panelGroup>

<h:outputText value="Nombre:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.nombre}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.nombre}" rendered="#{lazyBean.editMode}" required="true" label="Year"/>
</h:panelGroup>


<h:outputText value="Apellido Paterno:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.paterno}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.paterno}" rendered="#{lazyBean.editMode}" required="true" label="Year"/>
</h:panelGroup>


<h:outputText value="Apellido Materno:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.materno}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.materno}" rendered="#{lazyBean.editMode}" required="true" label="Year"/>
</h:panelGroup>


<h:outputText value="Telefono:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.telefono}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.telefono}" rendered="#{lazyBean.editMode}" required="true" label="Telefono">
<f:validateLength minimum="2" maximum="15"/>
</p:inputText>

</h:panelGroup>





<f:facet name="footer">
<p:outputPanel rendered="true" layout="block" style="text-align:right">
<p:commandButton rendered="#{lazyBean.editMode}" value="Guardar" actionListener="#{lazyBean.save()}"
oncomplete="onEditComplete(xhr,status,args)" image="ui-icon ui-icon-check">

</p:commandButton>

<p:commandButton value="Cancel" onclick="carDialog.hide()" type="button" image="ui-icon ui-icon-close"/>

</p:outputPanel>
</f:facet>
</h:panelGrid>

</p:dialog>




<p:confirmDialog message="Are you sure?" width="200" header="Confirm" severity="alert" widgetVar="confirmation" appendToBody="true">

<p:commandButton value="Yes sure" update="cars" actionListener="#{tableBean.delete}" oncomplete="confirmation.hide()"/>
<p:commandButton value="Not yet" onclick="confirmation.hide()" type="button" />

</p:confirmDialog>


</h:form>



</ui:define>

</ui:composition>

</body>
</html>

piogwi
Posts: 19
Joined: 29 Aug 2011, 08:31

08 Sep 2011, 13:30

Check with Firebug if any data is posted when you click save button in dialog.

Does dialog show correct data in edit mode after you click edit button in a row?

zilph
Posts: 7
Joined: 17 Jun 2011, 20:52

09 Sep 2011, 21:04

thanks for the help... tried it again using Firebug plugin.. and found some nested forms problems.. so not submitting correctly... in another forum.. found an example
that recommends how to avoid nested forms when using dialogs and using individual forms inside Dialogs to avoid these behaviors.. this is the code that worked...


<body>



<ui:composition template="./../WEB-INF/templates/plantillaRIDEP.xhtml">


<ui:define name="center">


<h:form id="form1">



<p:growl id="msgs" showDetail="true" />

<p:dataTable var="user" value="#{lazyBean.listarConductores()}" id="tbl"
rows="10" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,20,30,50"
rowKey="#{user.idlicencia}"
page=""
>






<p:column>
<f:facet name="header">
<h:outputText value="IdLicencia"/>
</f:facet>
<h:outputText value="#{user.idlicencia}"/>
</p:column>


<p:column>
<f:facet name="header">
<h:outputText value="Nombre"/>
</f:facet>
<h:outputText value="#{user.nombre}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="ApPaterno"/>
</f:facet>
<h:outputText value="#{user.paterno}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="ApMaterno"/>
</f:facet>
<h:outputText value="#{user.materno}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="curp"/>
</f:facet>
<h:outputText value="#{user.curp}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Folio"/>
</f:facet>
<h:outputText value="#{user.folio}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Ciudad"/>
</f:facet>
<h:outputText value="#{user.ciudad}"/>
</p:column>


<p:column>
<f:facet name="header">
<h:outputText value="Telefono"/>
</f:facet>
<h:outputText value="#{user.telefono}"/>
</p:column>


<p:column style="width:100px">
<h:panelGrid columns="3" styleClass="actions" cellpadding="2">
<p:commandButton update=":frmDialog:dialogPanel" oncomplete="carDialog.show()" image="ui-icon ui-icon-search" title="View">
<f:setPropertyActionListener value="#{user}" target="#{lazyBean.selectedPersona}" />
<f:setPropertyActionListener value="#{false}" target="#{lazyBean.editMode}" />
</p:commandButton>
<p:commandButton update=":frmDialog:dialogPanel" oncomplete="carDialog.show()" image="ui-icon ui-icon-pencil" title="Edit">
<f:setPropertyActionListener value="#{user}" target="#{lazyBean.selectedPersona}" />
<f:setPropertyActionListener value="#{true}" target="#{lazyBean.editMode}" />
</p:commandButton>

<p:commandButton update=":frmDialog:dialogPanel" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete">
<f:setPropertyActionListener value="#{user}" target="#{lazyBean.selectedPersona}" />
</p:commandButton>



</h:panelGrid>
</p:column>



</p:dataTable>





<h:panelGrid columns="2">
<p:panel header="Exportar Datos">

<h:commandLink>
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="tbl" fileName="personas" excludeColumns="0"/>
</h:commandLink>

<h:commandLink>
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="tbl" fileName="personas" excludeColumns="0"/>
</h:commandLink>



<h:commandLink>
<p:graphicImage value="/images/xml.png" />
<p:dataExporter type="xml" target="tbl" fileName="personas" excludeColumns="1,2"/>
</h:commandLink>


</p:panel>
</h:panelGrid>

</h:form>









<p:dialog header="Persona DEtallazo" closable="true" widgetVar="carDialog" appendToBody="true" resizable="false" id="carDlg"
showEffect="explode" hideEffect="explode" modal="true">
<h:form id="frmDialog">

<p:outputPanel id="dialogPanel">


<h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">



<h:outputText value="Folio:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.folio}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.folio}" rendered="#{lazyBean.editMode}" required="true" label="Model"/>
</h:panelGroup>

<h:outputText value="Nombre:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.nombre}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.nombre}" rendered="#{lazyBean.editMode}" required="true" label="Year"/>
</h:panelGroup>


<h:outputText value="Apellido Paterno:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.paterno}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.paterno}" rendered="#{lazyBean.editMode}" required="true" label="Year"/>
</h:panelGroup>


<h:outputText value="Apellido Materno:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.materno}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.materno}" rendered="#{lazyBean.editMode}" required="true" label="Year"/>
</h:panelGroup>


<h:outputText value="Telefono:" />
<h:panelGroup>
<h:outputText value="#{lazyBean.selectedPersona.telefono}" style="font-weight:bold" rendered="#{!lazyBean.editMode}"/>
<p:inputText value="#{lazyBean.selectedPersona.telefono}" rendered="#{lazyBean.editMode}" required="true" label="Telefono">
<f:validateLength minimum="2" maximum="15"/>
</p:inputText>

</h:panelGroup>





<f:facet name="footer">
<p:outputPanel rendered="true" layout="block" style="text-align:right">
<p:commandButton rendered="#{lazyBean.editMode}" update=":form1" value="Guardar" actionListener="#{lazyBean.save()}"
oncomplete="carDialog.hide()" image="ui-icon ui-icon-check">

</p:commandButton>

<p:commandButton value="Cancel" onclick="carDialog.hide()" type="button" image="ui-icon ui-icon-close"/>

</p:outputPanel>
</f:facet>
</h:panelGrid>

</p:outputPanel>
</h:form>
</p:dialog>




<p:confirmDialog message="Are you sure?" width="200" header="Confirm" severity="alert" widgetVar="confirmation" appendToBody="true">
<h:form id="frmConfirm">

<p:commandButton value="Yes sure" update="cars" actionListener="#{tableBean.delete}" oncomplete="confirmation.hide()"/>
<p:commandButton value="Not yet" onclick="confirmation.hide()" type="button" />
</h:form>
</p:confirmDialog>











<p:fieldset legend="Componente Info" toggleable="true" >



<utils:info2 styleClass="red" />

</p:fieldset>



</ui:define>

</ui:composition>

</body>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 44 guests