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
Related
I am using PrimeFaces 5. Trying to learn it.
I am working on this particular screen for almost 3 days and had no progress.
I read the showcase of Primefaces lots of times, but everything seems to be in order. It is possible that I am addicted to my code and can not see the answer, but it seems to be all liked because it is all associated with events, or so it seems.
Problems:
- My DropDown (selectOneMenu) does not respond to click events to show its options;
- The arrows that do the paging of my search results does not respond to click as well;
- The search button does not respond after the first search;
- The View buttons does not displays the dialog;
- The growl component is also not recieving updates;
I am supplying the link to download the sourcecode here
- https://dl.dropboxusercontent.com/u/5784798/par.7z
Here it is the form working
<h:form id="formularioResultadoUsuario">
<p:dataTable var="usuario"
value="#{adiminstraUsuarioView.lazyUsuarioDataModel}"
paginator="true" rows="10"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" rowKey="#{usuario.id}"
selectionMode="single"
selection="#{adiminstraUsuarioView.selectedUsuario}"
id="usuarioTable" lazy="true">
<p:ajax event="rowSelect"
listener="#{adiminstraUsuarioView.onRowSelect}"
update=":formularioResultadoUsuario:usuarioDetail"
oncomplete="PF('usuarioDialog').show()" />
<p:column headerText="Id" sortBy="#{usuario.id}"
filterBy="#{usuario.id}">
<h:outputText value="#{usuario.id}" />
</p:column>
<p:column headerText="Nome" sortBy="#{usuario.nome}"
filterBy="#{usuario.nome}">
<h:outputText value="#{usuario.nome}" />
</p:column>
<p:column headerText="Grupo" sortBy="#{usuario.grupo}"
filterBy="#{usuario.grupo}">
<h:outputText value="#{usuario.grupo}" />
</p:column>
<p:column headerText="Role" sortBy="#{usuario.role}"
filterBy="#{usuario.role}">
<h:outputText value="#{usuario.role}" />
</p:column>
<p:column headerText="Sistema" sortBy="#{usuario.sistema}"
filterBy="#{usuario.sistema}">
<h:outputText value="#{usuario.sistema}" />
</p:column>
<p:column headerText="Subsistema" sortBy="#{usuario.subsistema}"
filterBy="#{usuario.subsistema}">
<h:outputText value="#{usuario.subsistema}" />
</p:column>
</p:dataTable>
<p:dialog header="Car Detail" widgetVar="usuarioDialog" modal="true"
showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="usuarioDetail" style="text-align:center;">
<p:panelGrid columns="2"
rendered="#{not empty adiminstraUsuarioView.selectedUsuario}"
columnClasses="label,value">
<h:outputText value="Id:" />
<h:outputText value="#{adiminstraUsuarioView.selectedUsuario.id}" />
<h:outputText value="Nome" />
<h:outputText
value="#{adiminstraUsuarioView.selectedUsuario.nome}" />
<h:outputText value="Grupo:" />
<h:outputText
value="#{adiminstraUsuarioView.selectedUsuario.grupo}" />
<h:outputText value="Role:" />
<h:outputText
value="#{adiminstraUsuarioView.selectedUsuario.role}" />
<h:outputText value="Sistema:" />
<h:outputText
value="#{adiminstraUsuarioView.selectedUsuario.sistema}" />
<h:outputText value="Subsistema:" />
<h:outputText
value="#{adiminstraUsuarioView.selectedUsuario.subsistema}" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
This question already has an answer here:
Skip required validation and invoke the application
(1 answer)
Closed 7 years ago.
I have a p:ajax within a form which triggers on change event in a select. Also I have a separate submit button to submit the form.
The form contains multiple validations. I want to bypass all the validations during the p:ajax call. Instead all the validations should happen during form submission.
This is my form: Field1 and Field2 are mandatory. But these validations should be bypassed during p:ajax call which in turn renders Field3 based on the selected Field2 value.
How can I do this?
<h:body>
<h:form id="formId">
<p:outputPanel autoUpdate="true">
<p:message for="field1Id field2Id" />
<p:panel id="panelId">
<p:panelGrid>
<p:row>
<p:column>
<h:outputText value="Field1:" />
</p:column>
<p:column>
<p:inputText
id="field1Id"
required="true"
requiredMessage="Field1 is Required!"
value="#{testBean.field1}"
size="5"
maxlength="30" />
</p:column>
</p:row>
<p:row>
<p:column>
<h:outputText value="Field2:" />
</p:column>
<p:column>
<p:selectOneMenu
id="field2Id"
value="#{testBean.field2}"
required="true"
requiredMessage="Field2 is Required!">
<f:selectItems
value="#{testBean.fields}"
var="var1"
itemDescription="#{var1.description}"
itemLabel="#{var1.description}"
itemValue="#{var1.id}" />
<p:ajax
process="#form"
event="change" />
</p:selectOneMenu>
</p:column>
</p:row>
<p:row rendered="#{testBean.field2 > 0}">
<p:column>
<h:outputText value="Field3:" />
</p:column>
<p:column>
<p:inputText
value="#{testBean.field3}"
size="5"
maxlength="10" />
</p:column>
</p:row>
</p:panelGrid>
<p:commandButton
value="Save"
action="#{testBean.saveForm()}"
process="#form" />
</p:panel>
</p:outputPanel>
</h:form>
</h:body>
You can achieve by below code. My code just add binding attribute(binding="{save}") at the button, and also change required="true" to required="#{not empty param[save.clientId]}"
<h:body>
<h:form id="formId">
<p:outputPanel autoUpdate="true">
<p:message for="field1Id field2Id" />
<p:panel id="panelId">
<p:panelGrid>
<p:row>
<p:column>
<h:outputText value="Field1:" />
</p:column>
<p:column>
<p:inputText
id="field1Id"
required="#{not empty param[save.clientId]}"
requiredMessage="Field1 is Required!"
value="#{testBean.field1}"
size="5"
maxlength="30" />
</p:column>
</p:row>
<p:row>
<p:column>
<h:outputText value="Field2:" />
</p:column>
<p:column>
<p:selectOneMenu
id="field2Id"
value="#{testBean.field2}"
required="#{not empty param[save.clientId]}"
requiredMessage="Field2 is Required!">
<f:selectItems
value="#{testBean.fields}"
var="var1"
itemDescription="#{var1.description}"
itemLabel="#{var1.description}"
itemValue="#{var1.id}" />
<p:ajax
process="#form"
event="change" />
</p:selectOneMenu>
</p:column>
</p:row>
<p:row rendered="#{testBean.field2 > 0}">
<p:column>
<h:outputText value="Field3:" />
</p:column>
<p:column>
<p:inputText
value="#{testBean.field3}"
size="5"
maxlength="10" />
</p:column>
</p:row>
</p:panelGrid>
<p:commandButton
value="Save"
binding="{save}"
action="#{testBean.saveForm()}"
process="#form" />
</p:panel>
</p:outputPanel>
</h:form>
</h:body>
This approach is proposed by this link.
If you're willing to use omnifaces, there is an ignoreValidationFailed tag.
Check the example at omnifaces showcase:
<o:form>
...
<h:commandButton value="save valid data" action="#{bean.saveValidData}">
<o:ignoreValidationFailed />
<f:ajax execute="#form" />
</h:commandButton>
</o:form>
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 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>
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"