clear dialog box JSF - 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";
}

Related

f:setPropertyActionListener is not calling target in JSF

I am working on popup to pass some values but looks like the target is not triggering.
This is the button :
<p:column headerText="View" style="text-align: center;" width="80">
<p:commandButton update=":dialogueForm:uploadHistory" value="View"
oncomplete="PF('historyDialog').show()" icon="ui-icon-search"
title="View">
<f:setPropertyActionListener value="#{as}"
target="#{remoteDeployment.selectedTerminalRemoteDeploymentSettings}" />
</p:commandButton>
</p:column>
This is the dialogue box :
<p:dialog id="dlg" header="History" widgetVar="historyDialog"
showEffect="explode">
<h:form id="dialogueForm">
<p:outputPanel id="uploadHistory" style="text-align:center;">
<p:panelGrid columns="2"
rendered="#{not empty remoteDeployment.selectedTerminalRemoteDeploymentSettings}"
columnClasses="label,value">
<h:outputText value="Branch Name:" />
<p:inputText
value="#{remoteDeployment.selectedTerminalRemoteDeploymentSettings.terminalId}" />
</p:panelGrid>
</p:outputPanel>
</h:form>
</p:dialog>
selectedTerminalRemoteDeploymentSettings is always empty.
please help.

Selected values of selectBooleanCheckbox and selectoneradio is reset while navigating between tabs of tabview

I am trying to do a page with a few tabs, by using primefaces. But some some selected values are lost while navigating between tabs. Last tab contains 2 selectBooleanCheckboxes and 2 selectOneRadios and one of the selectoneradio grid is rendered according to checkbox value. When user selects among these 4 components and navigates between tabs radio button and check box selected values are lost. I am using #viewScoped at the bean part. For example if the user is viewing the 4th tab and wants to change something from third tab. When user navigates to the third tab and makes change on checkbox or radio button new values and previous values are reset. Form is uploading itself again I think. Why the values are lost?Is there a solution for this? Do I need something like converter?
my .xhtml is:
<h:form id="form">
<p:tabView id="tabPanel" dynamic="true" activeIndex="#{myBean.activeIndex}" cache="false">
<!-- FIRST TAB -->
<p:tab id="person" title="Person">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="name" />
<p:inputText value="???USERINFO???" label="Name" />
<p:commandButton value="NEXT" action="#{myBean.nextTab}" update=":form:tabPanel" />
</h:panelGrid>
</p:tab>
<!-- SECOND TAB -->
<p:tab id="adres" title="Address">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="Phone" />
<p:inputMask id="phone" value="???USERINFO???" mask="1999999999" required="true" requiredMessage="ERROR AT PHONE NUMBER"/>
<p:commandButton value="NEXT" action="#{myBean.nextTab}" update=":form:tabPanel" />
</h:panelGrid>
</p:tab>
<!-- THIRD TAB -->
<p:tab id="contact" title="Contact">
<h:panelGrid columns="2" cellpadding="10">
<h:panelGrid columns="3" style="margin-bottom:5px" cellpadding="5">
<h:outputText value="My Question: " />
<p:selectBooleanCheckbox value="#{myBean.myCheckBox}" />
<h:outputText value="Yes" />
<h:outputText value="My Second Question:" />
<p:selectBooleanCheckbox value="#{myBean.myCheckBox2}" />
<h:outputText value="No" />
</h:panelGrid>
<h:panelGrid id="panelGrid" columns="3" style="margin-bottom:10px" cellpadding="10">
<p:outputLabel value="My question"/>
<h:outputLabel for="radio"/>
<h:selectOneRadio id="radio" value="#{myBean.radioButton}" required="true" requiredMessage="ERROR">
<f:selectItem itemLabel="Yes" itemValue="Yes"/>
<f:selectItem itemLabel="No" itemValue="No"/>
<f:ajax execute="#this" render="idInfo"/>
</h:selectOneRadio>
</h:panelGrid>
<h:panelGroup id="idInfo">
<h:panelGrid columns="3" rendered="#{myBean.radioButton == 'No'}">
<h:outputText value="Chooses: " />
<h:selectOneRadio id="selectOneRadio" value="#{myBean.type}" layout="pageDirection">
<f:selectItem itemLabel="Choice 1" itemValue="choice1"/>
<f:selectItem itemLabel="Choice 2" itemValue="choice2"/>
<f:selectItem itemLabel="Choice 3" itemValue="choice3"/>
</h:selectOneRadio>
</h:panelGrid>
</h:panelGroup>
</h:panelGrid>
</p:tab>
</p:tabView>
</h:form>
<p:commandButton value="NEXT" action="#{myBean.nextTab}" update=":form:tabPanel" />
Add process to your button's process=":form:tabPanel" so the value is set to the property in backbean.

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>

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

Resources