primefaces datatable row returns null value after filtering - jsf

I have a primefaces datatable which displays a list of cars. One of the columns of the datatable has a command button which when clicked opens a dialog box which displays information about the selected car. Everything works as expected until I default filter the datatable and select the command button of a filtered row. The details of the car is null in this case. How can I get the value (car object) of the selected row after filtering?
<h:form id="carView">
<h:panelGrid id="carPanelGroup" style="width:100%" styleClass="tblNowrap100pct">
`<p:dataTable value="#{carBean.carList}" var="car" id="carTbl" stripedRows="true" rendered="#{not empty carBean.carList}" showGridlines="true" styleClass="tblNowrap100pct" filteredValue="#{carBean.filteredValues}" rowKey="#{car.carId}">
<p:column headerText="Car Name" sortBy="#{car.carName}" filterBy="#{car.carName}" filterMatchMode="contains" >
<f:facet name="header">
<h:outputText value="Car Name" />
</f:facet>
<h:outputText value="#{car.carName}" />
</p:column>
<p:column headerText="Make" sortBy="#{car.make}" filterBy="#{car.make}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Make" />
</f:facet>
<h:outputText value="#{car.make}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Car Download" />
</f:facet>
<p:commandButton action="#{carBean.selectCar}" value="Download" styleClass="linkButton" process="#this" oncomplete="PF('carDownloadpanel').show();" update="#all">
<f:setPropertyActionListener value="#{car}" target="#{carBean.carDto}"/>
</p:commandButton>
</p:column>`
</p:dataTable>
</p:panelGrid>
</h:form>
<!-- ******** pop up -->
<p:outputPanel id = "downloadOutputPanel">
<p:dialog header="#{carBean.carDto.carName}" widgetVar="carDownloadpanel" width="500" height="400" id="dialogDetails" modal="true">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="#{carBean.carDto.carName}" />
</h:panelGroup>
</f:facet>
<h:form id="carDetailView">
<p:panel>
<p:panelGrid id="carDetails" columns="2" styleClass="summaryTable"
columnClasses="colLabel, colNormalInputArea" rendered="#{not empty firmBean.firmDto}">
<h:outputText value="Car Name:" />
<h:outputText value="#{carBean.carDto.carName}" />
<h:outputText value="Firm Id:" />
<h:outputText value="#{carBean.carDto.carId}" />
</p:panelGrid>
</p:panel>
</h:form>
<h:form id="iwaInfo">
<h:panelGrid id="carReportInput" columns="2" styleClass="summaryTable" columnClasses="colLabel, colNormalInputArea">
<p:commandLink value="Download" id="downloadBtn"
action="#{carBean.downloadCar}" onclick="PF('carDownloadpanel').hide();">
</p:commandLink>
<p:commandLink value="Cancel" id="cancelBtn"
oncomplete="PF('carDownloadpanel').hide();" update=":carView:carPanelGroup" process="#parent"/>
</h:panelGrid>
</h:form>
</p:dialog>
</p:outputPanel>
Java method :
public String selectCar(){
if (this.carDto != null) {
carId = this.carDto.getCarId();
instanceId = this.carDto.getInstanceId();
if (carId!=null&&instanceId!=null){
CarDto dto = new CarDto();
List<CarDto> sLst = carService.searchCar(Long.parseLong(carId), Long.parseLong(instanceId));
if (sLst!=null&&sLst.size()>0){
dto= sLst.get(0);
}
setCarDto(dto);
}
}
return "";
}

Related

How can I use datatable selection in dialog widget in PrimeFaces?

I am trying to use datatable selection in dialog widget. But I cannot get selected value in my bean. Datatable selection is working, if I delete dialog widget tag. I am using PrimeFaces 4.0. How can I fix this?
passengerform.xhtml
<p:hotkey bind="esc" handler="dialogWidget.hide();" />
<p:dialog id="dialog" widgetVar="dialogWidget"
header="Coupon List" modal="true" width="400" showEffect="fade"
hideEffect="fade" appendTo="#(body)">
<h:form id="formDialog">
<h:outputLabel value="Lütfen E-ticket Kuponunu Seçiniz." />
<p:dataTable id="singleDT" var="coupon"
value="#{passengerFormService.couponList}"
rowKey="#{coupon.id}" rowIndexVar="rowIndex"
selection="#{passengerFormService.selectedCoupon}"
selectionMode="single">
<p:ajax event="rowSelect"
listener="#{passengerFormService.selectCoupon}"
update=":tab1:tab1_1:eticketform:formDialog">
<f:setPropertyActionListener value="#{coupon}"
target="#{passengerFormService.coupon}" />
</p:ajax>
<f:facet name="header"></f:facet>
<h:inputHidden name="hidden1"
value="#{passengerFormService.passengerForm.id}" />
<p:column style="width:20px" width="20">
<f:facet name="header">
<h:outputText value="#" />
</f:facet>
<h:outputText value="#{rowIndex+1}" />
</p:column>
<p:column headerText="Id">
<h:outputText value="#{coupon.id}" />
</p:column>
<p:column headerText="Departure Location">
<h:outputText value="#{coupon.departureLocation}" />
</p:column>
<f:facet name="footer"></f:facet>
</p:dataTable>
<p:separator />
<h:panelGrid columns="2" cellspacing="5"
columnClasses="alignLeft,alignRight" style="width:100%">
<p:commandButton id="selectButton1" update=""
icon="ui-icon-close" value="İptal"
oncomplete="PF('dialogWidget').hide()" />
<p:commandButton id="cancelSelectedButton1"
update=":tab1:tab1_1:passengerInsertform"
icon="ui-icon-check"
value="Onayla" oncomplete="PF('dialogWidget').hide()" />
</h:panelGrid>
</h:form>
</p:dialog>
PassengerFormService.java
public void selectCoupon(SelectEvent event) {
Log.getLogger().debug("New2 coupon selected...");
Log.getLogger().debug("selected: " +getSelectedCoupon());
}

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

Primefaces data exporter exports empty values in Excel

I try to export some data loded from database.
With the code below, the exported file shows empty values in all columns althought my variable marchebean.selectedmarche.marchetraveau contains values.
Is there anything wrong in my code ?
I'm using Primefaces 4.0 and this is my xhtml page
<h:form id="form">
<p:tabView>
<p:tab title="Visualiser ">
<p:panel>
<h:commandLink >
<p:commandButton value="exporter" />
<p:dataExporter type="xls" target="crs" fileName="prixde" pageOnly="true" />
</h:commandLink>
<p:dataTable id="crs" var="marche" value="#{marchebean.selectedmarche.marchetraveau}" >
<f:facet name="header">
Tbaleau des travaux
</f:facet>
<f:facet name="footer">
<h3> Total HTVA = #{marchebean.calculdetotaltravhtva()}</h3>
<h3> Total TTC = #{marchebean.calculdetotaltravttc()} </h3>
</f:facet>
<p:column headerText="article" width="10%" >
<h:outputText value="#{marche.traveaux.article}"/>
</p:column>
<p:column headerText="Désignation des traveaux" width="40%" >
<h:outputText value="#{marche.traveaux.designation}"/>
<h:outputText value="#{marche.traveaux.paragraph}"/>
</p:column>
<p:column headerText="Unité">
<h:outputText value="#{marche.traveaux.unite}"/>
</p:column>
<p:column headerText="PUHTVA">
<h:outputText value="#{marche.prixunitaire}"/>
</p:column>
<p:column headerText="PUTTC">
<h:outputText value="#{marchebean.calcultva(marche.prixunitaire)}" />
</p:column>
<p:column headerText="Qtt">
<h:outputText value="#{marche.quantite}"/>
</p:column>
<p:column headerText="MHTVA">
<h:outputText value="#{marchebean.calculmonthtva(marche.prixunitaire ,marche.quantite)}" />
</p:column>
<p:column headerText="MTTC">
<h:outputText value="#{marchebean.calculmontttc(marche.prixunitaire ,marche.quantite)}" />
</p:column>
</p:dataTable>
</p:panel>
</p:tab>
</p:tabView>
</h:form>
we need to provide the
<f:facet name="header>
<h:outputText value="aricle"/>
</f:facet>
then exporter will add the headers to your exported document.
<p:column headerText="article" width="10%" >
<f:facet name="header">
<h:outputText value="article" />
</f:facet>
<h:outputText value="#{car.traveaux.article}"/>
</p:column>
This works for me. Maybe it needs validation and that's why it's empty at the end. Adding immediate="true" skips the validation.
<h:form id="confColaForm" .....>
<p:dataTable id="tablacolas" ... >
<f:facet name="header">
<h:commandLink id="exportar" update=":confColaForm:tablacolas" style="align:right;" immediate="true" >
<h:graphicImage library="images" name="iconexcel.png" style="width:30px;height:30px; "
title="Exportar" />
<p:dataExporter type="xls" target="tablacolas" fileName="ConfiguracionColas" />
</h:commandLink>
</f:facet>
...(columns here)
</p:dataTable/>
</h:form>
possible reason may be the "managedbean scope"...
1)change scope to "view"
2)serialize managedbean
this worked for me

datatable paginator primefaces not working

I'm trying to include the paginator on my datatable but it's not working, i have the table and the paginator shows but it's not working, always int page 1 !!
this is my code :
![datatable paginator not working ][1]
<h:form id="form">
<p:outputPanel id="users">
<p:dataTable id="usersTable" value="#{personBean.allPersons}" paginator="true" rows="4" var="person" >
<p:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<p:commandLink action="#{personBean.editPerson}">
<h:outputText value="#{person.name}" />
<f:setPropertyActionListener target="#{personBean.person}"
value="#{person}" />
</p:commandLink>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Age" />
</f:facet>
<p:commandLink action="#{personBean.editPerson}">
<h:outputText value="#{person.age}" />
<f:setPropertyActionListener target="#{personBean.person}"
value="#{person}" />
</p:commandLink>
</p:column>
</p:dataTable>
</p:outputPanel>
<p:commandButton value="Create New User"
action="#{personBean.newPerson}" />
</h:form>
always i have the same table, i can't move to 2

PrimeFaces dataTable not updating after Ajax request

I'm currently working with a PrimeFaces dataTable and am trying endlessly to append a new to the dataTable immediately after the user adds it. Server-side, everything is working -- data is saved to both the database and hard disk. I'd like to see a partial-page update following the successful request, and I just can't seem to get it to work. Here is my XHTML code:
<div class="content">
<div id="mainContent">
<div class="topNav">
<h:form id="navForm">
<p:commandButton value="Upload"/>
<p:commandButton value="New Folder" onclick="createDlg.show();" />
<p:commandButton value="Delete Folder" action="#" />
</h:form>
</div>
<div id="filePanel">
<h:form id="dataTable" prependId="false">
<p:dialog header="Create" widgetVar="createDlg" modal="true" height="200">
<p:panel header="New Folder">
<h:panelGrid columns="2">
<h:outputLabel value="Name:" for="txt_name"></h:outputLabel>
<p:inputText id="txt_name" value="#{directoryController.newDir.name}" required="true" />
<p:commandButton value="Create" actionListener="#{directoryController.createNew}" update="dGrid" oncomplete="createDlg.hide();"/>
<p:ajaxStatus style="width:16px; height:16px;">
<f:facet name="start">
<h:outputText value="Saving..." />
</f:facet>
<f:facet name="">
<h:outputText value="Complete." />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
</p:panel>
</p:dialog>
<p:dataTable id="dGrid" value="#{directoryController.itemsByOwner}" var="dir">
<p:column selectionMode="multiple"/>
<p:column sortBy="#{dir.name}">
<f:facet name="header">
File Name
</f:facet>
<h:outputText value="#{dir.name}" />
</p:column>
<p:column>
<f:facet name="header">
File Size
</f:facet>
</p:column>
</p:dataTable>
</h:form>
</div>
</div>
</div>
And finally, here is my backing bean.
public String createNew(){
newDir.setDateCreated(new Date());
newDir.setDateModified(new Date());
newDir.setId(BigDecimal.ZERO);
newDir.setLocation(ROOT_DIRECTORY + currentUser.getUsername() + "/");
newDir.setFilesCollection(f);
newDir.setDescription("");
newDir.setOwner(currentUser);
current = newDir;
create();
persistDirectoryFromObject(newDir);
newDir = new Directory();
RequestContext.getCurrentInstance().addPartialUpdateTarget("dGrid");
return null;
}
If you are using 3.0.M4 you could do:
...
...
<p:outputPanel autoUpdate="true">
<p:dataTable id="dGrid" value="#{directoryController.itemsByOwner}" var="dir">
<p:column selectionMode="multiple"/>
<p:column sortBy="#{dir.name}">
<f:facet name="header">
File Name
</f:facet>
<h:outputText value="#{dir.name}" />
</p:column>
<p:column>
<f:facet name="header">
File Size
</f:facet>
</p:column>
</p:dataTable>
</p:outputPanel>
or you could simply:
<p:commandButton value="Create" action="#{directoryController.createNew}" oncomplete="createDlg.hide();" ajax="false" />

Resources