I need your help on JSF2. I made a datatable to list data items from database. I want to select an item from that list an print it on an edit dialog. The problem is that the item's data is'nt shown on that dialog. Here is JSF code used to generate it:
<p:dataTable value="#{airportController.items}" var="item" style="border: 0px;">
<f:facet name="header">Airports</f:facet>
<p:column>
<f:facet name="header">ID</f:facet>
<h:outputText value="#{item.airportId}"/>
</p:column>
<p:column>
<f:facet name="header"></f:facet>
<p:commandButton title="View" value="" update=":airportForm:airportEditForm" icon="edit_icon.gif"oncomplete="editAirportDlg.show();">
<f:setPropertyActionListener value="#{item}" target="#{airportController.selected}"/>
</p:commandButton>
</p:column>
<p:commandButton value="Ajouter" onclick="createAirportDgl.show();"/>
</p:dataTable>
<p:dialog id="airportEditForm" widgetVar="editAirportDlg" modal="false" header="Modifier" rendered="true" resizable="false">
<h:panelGrid id="airportDisplay" columns="2" paginator="true" rows="10" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15">
<h:outputText value="Pays"/>
<p:inputText value="#{airportController.selected.country}"/>
<h:outputText value="Ville"/>
<p:inputText value="#{airportController.selected.city}"/>
<h:outputText value="Nom"/>
<p:inputText value="#{airportController.selected.name}"/>
<h:outputText value="Addresse"/>
<p:inputText value="#{airportController.selected.hqAddress}"/>
<p:commandButton value="Valider" action="#{airportController.update()}"/>
</h:panelGrid>
</p:dialog>
All that is put all together in the index.xhtml page.
I don't know what i did wrong.
Could you send the whole xhtml content? This could be a validation problem. Try to use process="#this" on the commandButton and update the airportDisplay instead.
<p:commandButton title="View" value=""
update=":airportForm:airportDisplay"
icon="edit_icon.gif"oncomplete="editAirportDlg.show();" process="#this">
<f:setPropertyActionListener value="#{item}" target="#{airportController.selected}"/>
</p:commandButton>
Try to put everything i.e your datatable and dialog inside h:form with id and then
on edit button click update your dialog with respect to grid id like :form:airportDisplay also shown in below.
<h:form id="form">
<p:growl id="growl" showDetail="true" life="3000"/>
<p:dataTable value="#{airportController.items}" var="item" style="border: 0px;">
<f:facet name="header">Airports</f:facet>
<p:column>
<f:facet name="header">ID</f:facet>
<h:outputText value="#{item.airportId}"/>
</p:column>
<p:column>
<f:facet name="header"></f:facet>
<p:commandButton title="View" value="" update=":form:airportDisplay" icon="edit_icon.gif"oncomplete="editAirportDlg.show();">
<f:setPropertyActionListener value="#{item}" target="#{airportController.selected}"/>
</p:commandButton>
</p:column>
<p:commandButton value="Ajouter" onclick="createAirportDgl.show();"/>
</p:dataTable>
<p:dialog id="airportEditForm" widgetVar="editAirportDlg" modal="false" header="Modifier" rendered="true" resizable="false">
<h:panelGrid id="airportDisplay" columns="2" paginator="true" rows="10" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15">
<h:outputText value="Pays"/>
<p:inputText value="#{airportController.selected.country}"/>
<h:outputText value="Ville"/>
<p:inputText value="#{airportController.selected.city}"/>
<h:outputText value="Nom"/>
<p:inputText value="#{airportController.selected.name}"/>
<h:outputText value="Addresse"/>
<p:inputText value="#{airportController.selected.hqAddress}"/>
<p:commandButton value="Valider" action="#{airportController.update()}"/>
</h:panelGrid>
</p:dialog>
</h:form>
Thanks for help, here is page content,
index.xhtml
<ui:define name="title">
Airports
</ui:define>
<ui:define name="header">
header
</ui:define>
<ui:define name="menu">
menu
</ui:define>
<ui:define name="content">
<h:form id="airportForm">
<ui:include src="list.xhtml"/>
<ui:include src="edit.xhtml"/>
<ui:include src="create.xhtml"/>
</h:form>
</ui:define> </ui:composition>
list.xhtml
<p:dataTable value="#{airportController.items}" var="item" style="border: 0px;" >paginator="true"
rowKey="#{item.airportId}" selection="#{airportController.selected}" >selectionMode="single"
sortBy="#{item.airportId}">
Airports
ID
Nom
Pays
Ville
Addesse
onclick="editAirportDlg.show();"/>
update=":airportForm:airportCreateForm"
onclick="createAirportDgl.show();"/>
edit.xhtml
<p:dialog widgetVar="editAirportDlg" modal="false"
header="Modifier" rendered="true" resizable="false">
<h:form id="airportEditForm">
<h:panelGrid columns="2">
<h:outputText value="Pays :"/>
<p:inputText value="#{airportController.selected.country}"/>
<h:outputText value="Ville: "/>
<p:inputText value="#{airportController.selected.city}"/>
<h:outputText value="Nom: "/>
<p:inputText value="#{airportController.selected.name}"/>
<h:outputText value="Addresse: "/>
<p:inputText value="#{airportController.selected.hqAddress}"/>
<f:facet name="footer">
<p:commandButton value="Valider" icon="ui-icon-disk" action=" {airportController.update()}"/>
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog> </ui:composition>
Related
I am using JSF 2.2 with PrimeFaces 5.0. I have a dataTable with cell-editing.
I am having problems with the dataTable inside dialog when I set editMode="cell", the outputtext after editing it's doesn't appear, but when i put the datatable edit outside dialog, it's work.When I inspect the element of datatable
<div class="ui-cell-editor-output" style="display: none;"></div> it's empty but if i put the datatable edtor outside dialog the outPut element isn't empty
Let me explain with some code:
<p:dialog id="modif" width="80%" widgetVar="w_edit" modal="true" >
<p:tabView >
<p:tab title="Controle de Réception ">
<h:panelGrid>
<p:dataTable id="data1" value="#{normeMicroEBean.listOfNorme(lotRecpBean.currentLotReception.entrant)}"
var="item" editable="true" editMode="cell" >
<p:column headerText="Valeur Controle" styleClass="ui-editable-column">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{item.valeurControle}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{item.valeurControle}" style="width: 50%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column width="15%" headerText="Testeur">
<p:cellEditor >
<f:facet name="output"><h:outputText value="#{item.testeurCR.nom}" /></f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{item.testeurCR.nom}" style="width:50%">
<f:selectItems value="#{personnelBean.liste}" var="perso" itemLabel="#{perso.nom}" itemValue="#{perso}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:panelGrid>
</p:tab>
</p:tabView>
</p:dialog>
I hope (like always) any of you could save me again.
All user input must be inside of a form. You'll need an <h:form> inside the dialog.
I still have the same problem when i modify the row in datatable editor inside dialog the outputtext doesn't change still have the old value ,but when i put this datatable in simple page work
<p:dialog id="modif" width="80%" widgetVar="w_edit" modal="true" >
<p:tabView >
<p:tab title="Controle de Réception ">
<h:form>
<h:panelGrid>
<p:dataTable id="data1" value="#{normeMicroEBean.listOfNorme(lotRecpBean.currentLotReception.entrant)}"
var="item" editable="true" editMode="cell" >
<p:column headerText="Valeur Controle" styleClass="ui-editable-column">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{item.valeurControle}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{item.valeurControle}" style="width: 50%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column width="15%" headerText="Testeur">
<p:cellEditor >
<f:facet name="output"><h:outputText value="#{item.testeurCR.nom}" /></f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{item.testeurCR.nom}" style="width:50%">
<f:selectItems value="#{personnelBean.liste}" var="perso" itemLabel="#{perso.nom}" itemValue="#{perso}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:panelGrid>
<h:form>
</p:tab>
<p:tab title="Info lot de Réception">
<h:form>
<p:panelGrid id="idPanel">
<p:row>
<p:column><p:outputLabel value="QuantiteLivree:" for="quantiteLivree" /></p:column>
<p:column><p:inputText id="quantiteLivree" value="#{lotRecpBean.currentLotReception.quantiteLivree}" title="QuantiteLivree" /></p:column>
<p:column><p:outputLabel value="QuantiteRecue:" for="quantiteRecue" /></p:column>
<p:column><p:inputText id="quantiteRecue" value="#{lotRecpBean.currentLotReception.quantiteRecue}" title="QuantiteRecue" /></p:column>
<p:column><p:outputLabel value="NumBonLivraison:" for="numBonLivraison" /></p:column>
<p:column><p:inputText id="numBonLivraison" value="#{lotRecpBean.currentLotReception.numBonLivraison}" title="NumBonLivraison" /></p:column>
</p:row>
</p:panelGrid>
<div>
<p:commandButton action="#{lotRecpBean.update()}" value="Enregistrer" styleClass="button"
style="float: right" oncomplete="PF('lotRecepTable').filter();PF('w_edit').hide();" />
</div>
</h:form>
</p:tab>
</p:tabView>
</p:dialog>
I fixed the problem , it's come from the value of datatable ===> the value of datatable editor must be a list and not a method which return a list datatable editor work just with a list 1-
<p:dataTable id="data1" value="#{normeMicroEBean.listOfNorme}"
var="item" editable="true" editMode="cell" >
I create a list in the managed bean t and in the button i execute the method to full the list created in the managed bean . thank you for your response
I am using jsf 2.0 and primeface 3.5;
i am displaying a datatable and on the selection of any row, i display details in dailogue box. now the problem is when the page is loaded, and for the first time i select any row , the dialogue display nothing, but after that it works properly, what can be the reason of this issue
<h:body>
<h:form id="form">
<p:dataTable var="row"
value="#{user.list}" paginator="true"
rows="10" selection="#{user.selectedUser}"
filteredValue="#{user.filteredUser}" rowKey="#{row.attackID}"
rowsPerPageTemplate="5,10,15" selectionMode="single" paginatorPosition="bottom">
<p:ajax event="rowSelect" update=":form:display"
oncomplete="dlg.show()" listener="#{user.selected()}"/>
<p:column headerText="User-ID" filterBy="#{row.userID}">
<h:outputText value="#{row.userID}" />
</p:column>
<p:column headerText="Name" filterBy="#{row.userName}">
<h:outputText value="#{row.userName}" />
</p:column>
<p:column headerText="Threat" filterBy="#{row.attackID}">
<h:outputText value="#{row.attackID}" />
</p:column>
<p:column headerText="Rank">
<h:outputText value="#{row.rank}" />
</p:column>
</p:dataTable>
<p:dialog id="tDialog" header="Threat info" widgetVar="dlg"
modal="true" height="250" width="300" showEffect="explode"
hideEffect="explode">
<h:panelGrid id="display" columns="2" cellpadding="4">
<h:outputText value="Attack ID:" />
<h:outputText value="#{user.selectedUser.attackID} " />
<h:outputText value="Name:" />
<h:outputText value="#{user.selectedUser.attackName}" />
<h:outputText value="Action Taken:" />
<h:outputText value="#{user.selectedUser.actionTaken}" />
<h:outputText value="Attack Time:" />
<h:outputText value="#{user.selectedUser.attackTime }" />
</h:panelGrid>
</p:dialog>
</h:form>
</h:body>
I've a CommandButton component inside Datatable, which is within a TabView component. ActionListener method of CommandButton component don't work. Never is fired.
This is my XHTML page:
<p:dialog id="dlgView" widgetVar="wvDlgView"
modal="true" closable="true" resizable="false">
<p:outputPanel id="opViewUser">
<h:form>
<p:tabView id="tabViewUser">
<p:tab title="DATOS PERSONALES">
<p:dataTable id="dtUsuarios" rows="5" paginator="true"
selectionMode="single" selection="#{personController.system}">
....
<p:column>
<p:commandButton value="Bloquear" actionListener="#{personController.block}" />
</p:column>
</p:dataTable>
</p:tab>
<p:tabView>
</h:form>
</p:outputPanel>
</p:dialog>
Thanks in advance :)
PD: PF 3.5, JSF (Mojarra) 2.1.3, Tomcat: 6.0.10
Sorry for not posting completely code and answer later. At any rate I think already it isn't necessary because I solved my problem. Explain in more detail the problem:
I had a structure similar to this on tab component:
<p:tab>
<h:form id="formTab" prependId="false">
<h:panelGrid columns="3">
<p:outputLabel value="Sistema " for="sltSystem"/>
<p:selectOneMenu id="sltSistema" required="true"
value="#{personController.idSistema}" >
<f:selectItems value="#{personController.listSistemas"
var="s" itemLabel="#{s.valor}" itemValue="#{s.id}"/>
</p:selectOneMenu>
<p:outputLabel value="Rol " for="sltRol"/>
<p:selectOneMenu id="sltRol" required="true"
value="#{personController.idRol}" >
<f:selectItems value="#{personController.listRoles}"
var="r" itemLabel="#{r.valor}" itemValue="#{r.id}"/>
</p:selectOneMenu>
</h:panelGrid>
<p:dataTable id="dtUsersSystems" rows="5" paginator="true"
value="#{personController.userSystems}" var="s" rowKey="#{s.id}" >
<p:column headerText="SISTEMA">
<h:outputText value="#{s.sistema}" />
</p:column>
<p:column headerText="ROL">
<h:outputText value="#{s.rol}" />
</p:column>
<p:column headerText="ESTADO">
<h:outputText value="#{s.estado}"/>
</p:column>
<p:column>
<p:commandButton value="Bloquear" icon="ui-icon-cancel" actionListener="#{personController.blocked}"></p:commandButton>
</p:column>
</p:dataTable>
<h:form>
</p:tab>
As you can see sltSystem and sltRol components have required attribute in true. For that when I clicked on button "Bloquear" its ActionListener method not was invoked because after I should select a value on sltSystem and sltRol components.
Therefore new page structure is this:
<p:tab>
<h:form id="formSelect" prependId="false">
<h:panelGrid columns="3">
<p:outputLabel value="Sistema " for="sltSystem"/>
<p:selectOneMenu id="sltSistema" required="true"
value="#{personController.idSistema}" >
<f:selectItems value="#{personController.listSistemas"
var="s" itemLabel="#{s.valor}" itemValue="#{s.id}"/>
</p:selectOneMenu>
<p:outputLabel value="Rol " for="sltRol"/>
<p:selectOneMenu id="sltRol" required="true"
value="#{personController.idRol}" >
<f:selectItems value="#{personController.listRoles}"
var="r" itemLabel="#{r.valor}" itemValue="#{r.id}"/>
</p:selectOneMenu>
</h:panelGrid>
</h:form>
<h:form id="formDataTable" prependId="false">
<p:dataTable id="dtUsersSystems" rows="5" paginator="true"
value="#{personController.userSystems}" var="s" rowKey="#{s.id}" >
<p:column headerText="SISTEMA">
<h:outputText value="#{s.sistema}" />
</p:column>
<p:column headerText="ROL">
<h:outputText value="#{s.rol}" />
</p:column>
<p:column headerText="ESTADO">
<p:graphicImage value="#{s.estado}"/>
</p:column>
<p:column>
<p:commandButton value="Bloquear" icon="ui-icon-cancel" actionListener="#{personController.blocked}"></p:commandButton>
</p:column>
</p:dataTable>
<h:form>
</p:tab>
A form for selectonemenu components and other form for datatable component.
Thanks to all :)
Hi i need to create a accordian panel with a datatable inside the tab1 but i am geeting the following error:: javax.Servlet.ServletException:cannot find component with identifier ":form:display" ,can anyone plz help me out to resolve this error using primefaces.i need to work without using widgets.
view.xhtml
<h:form prependId="false" id="form">
<p:dataTable id="dataTable" var="car" value="#{tableBean.getList()}"
paginator="true" rows="10" selectionMode="single" selection="#{tableBean.selectedCar}" rowKey="#{car.model}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<f:facet name="header">
Posted Jobs
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Model" />
</f:facet>
<h:outputText value="#{car.model}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Year" />
</f:facet>
<h:outputText value="#{car.year}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Manufacturer" />
</f:facet>
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Color" />
</f:facet>
<h:outputText value="#{car.color}" />
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":form:display" oncomplete="carDialog.show()" actionListener="#{tableBean.add}"
/>
</f:facet>
</p:dataTable>
<p:dialog id="dialog" header="Car Detail" widgetVar="carDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold">
<h:panelGrid id="display" columns="2" cellpadding="4">
<h:outputText value="Model:" />
<h:outputText value="#{tableBean.selectedCar.model}" />
<h:outputText value="Year:" />
<h:outputText value="#{tableBean.selectedCar.year}" />
<h:outputText value="Manufacturer:" />
<h:outputText value="#{tableBean.selectedCar.manufacturer}" />
<h:outputText value="Color:" />
<h:outputText value="#{tableBean.selectedCar.color}" />
</h:panelGrid>
</p:dialog>
</h:form>
AccordionPanel.xhtml
<h:head>
<title>Accordion Panel</title>
</h:head>
<h:body>
<h:form>
<p:accordionPanel>
<p:tab id="DataTable1" title="DataTable 1">
<ui:include src="view.xhtml" />
</p:tab>
<p:tab id="DataTable2" title="DataTable2">
</p:tab>
</p:accordionPanel>
</h:form>
</h:body>
</html>
You are getting this error because the update target of your commandButton can not be found using the specified component reference on the rendered html.
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":form:display" oncomplete="carDialog.show()" actionListener="#tableBean.add}"/>
Try removing the update=":form:display" so that your page can render, check the generated component id of the display panelGrid with Firebug and use that id in your update target.
Since primefaces version 3.1 component referencing is aligned with the JSF Spec. See this link for further information UI Component findComponent()
update your (update=":form:display") attribute on commandButton to this :
update=":form:dialog:display"
I have see this problem.Please see my jsf page.
<h:form id="companyList">
<p:contextMenu for="companiesDB" style="height:53px;">
<p:menuitem value=" edit" update="panelGrid" icon="ui-icon-pencil" oncomplete="editCompany.show()" />
<p:menuitem value=" delete" update="panelGrid" icon="ui-icon-closethick" onclick="editCompany.show()" />
</p:contextMenu>
<p:dataTable id="companiesDB" var="companies"
value="#{companyController.companyList}" rowKey="#{companies.pkId}"
selection="#{companyController.selectedCompany}"
selectionMode="single" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rows="20" >
<p:column headerText="name">
#{companies.companyName}
</p:column>
<p:column headerText="desc">
#{companies.description}
</p:column>
</p:dataTable>
<p:dialog header="edit mode" widgetVar="editCompany"
modal="true" height="160" width="390"
id="dialog" resizable="false">
<p:panelGrid cellpadding="10" id="panelGrid" >
<p:row>
<p:column width="300">
<h:outputText value="name:" style="float:left;" />
</p:column>
<p:column>
<p:inputText value="#{companyController.selectedCompany.companyName}"/>
</p:column>
</p:row>
<p:row>
<p:column>
<h:outputText value="desc:" style="float:right;" />
</p:column>
<p:column>
<p:inputText
value="#{companyController.selectedCompany.description}" />
</p:column>
</p:row>
</p:panelGrid>
<br />
<br />
<p:commandButton value="save" icon="ui-icon-check"
style="float:right; margin-right:25px;" update="companiesDB"
oncomplete="addCompany.hide();"
action="#{companyController.insertCompany()}">
</p:commandButton>
</p:dialog>
</h:form>
And console error was :
/company.xhtml #46,91 value="#{companyController.selectedCompany.companyName}": Target Unreachable, 'selectedCompany' returned null
try renaming your dialog id to mydialog (just to be on a safe side)
and update your menu item entry as following (notice the update="mydialog"):
<p:menuitem value="edit" update="mydialog" icon="ui-icon-pencil" oncomplete="editCompany.show()" />
also , make sure the edit button will be enabled only after a selection in table was made... otherwise you will get the null pointer...
you can achieve it with something like
<p:menuitem value="edit" disabled=#{companyController.selectedCompany eq null}.....
and add two p:ajax in your table
<p:dataTable.......>
<p:ajax event="rowSelect" update="contextMenuID" />
<p:ajax event="rowUnselect" update="contextMenuID" />
last thing : add id=contextMenuID to your context menu