PrimeFaces' rowEditor doesn't work other than first try - primefaces

I have a p:dataTable looks like this.
<p:remoteCommand name="rowEdit" action="#{servicesController.onRowEditCommand}" update="servicesTable" />
<p:remoteCommand name="rowEditCancel" action="#{servicesController.onRowEditCancelCommand}" update="servicesTable" />
<p:dataTable id="servicesTable"
value="#{servicesController.services}" var="service" rowKey="#{service.id}"
editable="true" editMode="row">
<p:ajax event="rowEdit" listener="#{servicesController.onRowEdit}"
oncomplete="rowEditCommand()"/>
<p:ajax event="rowEditCancel" listener="#{servicesController.onRowEditCancel}"
oncomplete="rowEditCancelCommand()"/>
<p:ajax event="rowSelect" update=":mainMenu"
listener="#{servicesController.sessionScopeServiceChanged}"/>
<!-- other columns here -->
<p:column style="width: 44px;">
<p:rowEditor/>
</p:column>
<!-- other columns here -->
</p:dataTable>
The p:rowEditor works fine for the first time. And it doesn't work from the second time. It gets to edit mode but the checkbox and x doesn't respond.

Two command names were wrong.
<p:remoteCommand name="rowEdit" ... />
<p:remoteCommand name="rowEditCancel" ... />
<p:ajax ... oncomplete="rowEditCommand()"/>
<p:ajax ... oncomplete="rowEditCancelCommand()"/>
I changed to.
<p:remoteCommand name="rowEditCommand" ... />
<p:remoteCommand name="rowEditCancelCommand" ... />
<p:ajax ... oncomplete="rowEditCommand()"/>
<p:ajax ... oncomplete="rowEditCancelCommand()"/>

Related

Primefaces Datatable Radiobutton submitting wrong values

I got a datatable with a custom layout selectoneradio. It doesnt submit correct values after the first row.
This is the datatable:
<h:form id="dataTableForm">
<br />
<p:dataTable id="absenceTable" var="absence" widgetVar="absenceTable"
value="#{adminController.absenceList}" rowIndexVar="rowIndex"
emptyMessage="Keine Absenzen mit ausstehender Genehmigung gefunden"
style="width:70%;margin-left:15%;margin-right:15%;margin-bottom:20px;margin-top:10px;"
rowKey="#{absence.id}" rows="30" paginator="true"
paginatorPosition="bottom" paginatorAlwaysVisible="false"
paginatorTemplate="{PageLinks}" sortBy="#{absence.startDate}"
sortOrder="descending"
filteredValue="#{adminController.filteredAbsences}">
<f:facet name="header">Mitarbeiterabsenzen mit ausstehender Genehmigung</f:facet>
<p:column>
<p:selectOneRadio id="action" value="#{absence.status}" required="false"
layout="custom" >
<f:selectItem itemValue="PENDING" noSelectionOption="true" />
<f:selectItem itemValue="APPROVED" />
<f:selectItem itemValue="REJECTED" />
<p:ajax event="valueChange" immediate="true" listener="#{adminController.checkBoxListener}" />
</p:selectOneRadio>
</p:column>
<p:column width="20">
<p:radioButton for="action" itemIndex="0" />
</p:column>
<p:column width="20">
<p:radioButton for="action" itemIndex="1" />
</p:column>
<p:column width="20">
<p:radioButton for="action" itemIndex="2" />
</p:column>
<f:facet name="footer">
<p:commandButton value="Speichern"
action="#{adminController.save()}" update="absenceTable" />
</f:facet>
</p:dataTable>
</h:form>
The row index and absence loop variable is defined on the datatable.
Its all in the same form.
The problem is, somehow, it only works for the first row. The other rows submit "on" instead of the value. I found in the generated html that they are not provided with value-tag like the radiobuttons in the first row are:
I guess its gonna be a stupid syntax issue or something... This is what i get debugging clicking on anything but the first row:
Im running on PF 5.2
This is a bug in PF5.2
The code runs smoothly on PF5.3

How to do conditional polling in primefaces?

I want to do conditional Polling in Primefaces (Version:6.0.0).
Here is the polling code:
<p:poll interval="20" update="liveChart,chrtTC_Cnt_Status,chrtStatus" />
For Example, I am field call Status. If status value is 'In-Progress' then only polling should start. Or else it should not do polling.
Here is my field code, if this value changed to 'In-Progress' then polling should start or else not
<p:outputLabel value="Status:" />
<p:outputLabel id="lblCurrentStatus" value="#{backingBean.status}" />
Here is my Xhtml code
<h:panelGrid columns="2" width="400">
<p:outputLabel for="lblStudentName" value="Select Other StudentName: " />
<p:selectOneMenu id="lblStudentName" style="width:250px"
value="#{backingBean.selectedStudent}"
panelStyle="width:180px" effect="fade" filter="true"
filterMatchMode="startsWith">
<f:selectItem itemLabel="Select One" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{backingBean.studentItemList}" />
<p:ajax
listener="#{backingBean.OnChangeOtherStudentDropDown}"
update=":idForm:tabStatus:p1,:idForm:tabStatus:p4,growl"
process="#form" />
</p:selectOneMenu>
<p:tabView id="tabStatus">
<p:tab title="Status" id="idStatusTab">
<h:panelGrid columns="3" cellpadding="10" id="p1">
<p:growl id="growl" showDetail="true" />
<p:ajaxStatus onstart="PF('statusDialog').show()"
onsuccess="PF('statusDialog').hide()" />
<p:dialog widgetVar="statusDialog" draggable="false"
closable="false" resizable="false" showHeader="false">
<h:graphicImage value="/images/ajax-loader.gif" />
</p:dialog>
<h:panelGrid columns="2" cellpadding="5" id="p2">
<p:outputLabel value="Failed:" />
<p:outputLabel id="lblCurrentFailed"
value="#{backingBean.intCurrentFailedStudent}" />
<p:outputLabel value="Processed:" />
<p:outputLabel id="lblCurrentProcess"
value="#{backingBean.intCurrentPassedStudent}" />
<p:outputLabel value="Status:" />
<p:outputLabel id="lblCurrentStatus"
value="#{backingBean.status}" />
</h:panelGrid>
<h:panelGrid columns="2" cellpadding="10" id="p3">
<p:chart type="pie" model="#{backingBean.pieModel1}"
rendered="#{not empty backingBean.pieModel1}"
id="chrtStatus" style="width:300px;height:200px">
</p:chart>
<br />
</h:panelGrid>
</h:panelGrid>
<h:panelGrid columns="3" cellpadding="10" id="p4">
<p:poll interval="20" update="liveChart,chrtTC_Cnt_Status,chrtStatus" />
<p:chart type="line"
model="#{backingBean.lineCurrentLineChart}"
rendered="#{not empty backingBean.lineCurrentLineChart}"
id="liveChart" style="height:500px;width:500px" />
<p:chart type="bar"
model="#{backingBean.barStatusCountStudent}"
rendered="#{not empty backingBean.barStatusCountStudent}"
id="chrtTC_Cnt_Status" style="width:500px;height:500px">
<p:ajax event="itemSelect" listener="#{backingBean.itemSelect}" />
</p:chart>
</h:panelGrid>
</p:tab>
</p:tabView>
</h:form>
Solution 1:
Wrap your p:poll within h:panelGroup or h:panelGrid, set rendered="#{backingBean.status eq 'In-Progress'}" on panel and update panel on changing of status, that will reset your polling.
Solution 2:
If you want to manually start and stop the polling then you need to set autoStart="false" and add widgetVar="statusPoll" attributes on p:poll and by invoking PF('statusPoll').start(); and PF('statusPoll').stop(); on changing the value of status field.
It is working,
<h:panelGrid columns="1" id="ID_polling" rendered="#{BackingBean.status eq 'In-Progress'}">
<p:poll interval="20" update="liveChart,chrtTC_Cnt_Status,chrtStatus" />
</h:panelGrid>
When I write this Panel, Panel will display only when status = 'In-Progress' or else it will not display.
Thank you again,

p:dataTable AutoComplete and ColumnToggler combination

When using autoComplete and columnToggler within a dataTable, I get a broken column-list in the column toggler.
That means, the column-list doesn't show the column-names but some javascript code instead (for each column).
Here is an example:
<p:commandButton id="showColsButton" type="button" value="Show Columns" />
<p:columnToggler datasource="myDataTable" trigger="showColsButton" />
<p:dataTable id="myDataTable" var="row" ...>
<p:column sortBy="#{row.myCol1}">
<f:facet name="header">
<div><h:outputText value="My Column 01" /></div>
<p:autoComplete ...>
<p:ajax event="itemSelect" update="myDataTable" />
</p:autoComplete>
</f:facet>
<h:outputText value="#{row.myCol1}" />
</p:column>
</p:dataTable>
Is this a bug or is there any solution for this specific problem?
Putting an input in the header facet is not valid. If you want to use it as a filter or something, put it in a f:facet name="filter".
<p:dataTable id="myDataTable" var="row" ...>
<p:column filterBy="#{row.myCol1}" sortBy="#{row.myCol1}">
<f:facet name="header">
<div><h:outputText value="My Column 01" /></div>
</f:facet>
<f:facet name="filter">
<p:autoComplete ...>
<p:ajax event="itemSelect" update="myDataTable" />
</p:autoComplete>
</f:facet>
<h:outputText value="#{row.myCol1}" />
</p:column>
But you might need to improve on the way the filter is used by not using the p:ajax but use an onchange=PF('dataTableWidget').filter(), adding a widgetVar attribute and adding filter attributes
See also
PrimeFaces showcase dataTable filter

BlockUI is not triggered when trigger is in a p:column

I am using buttons in a p:datatable and they are triggering a p:blockUI (PF 6.0)
When located in the footer of my datatable, the button does trigger the blockUI. When moved into a column, it does not trigger it
BlockUI
<p:blockUI block="blockPanel"
trigger="myForm:myTable:myButton myForm:myTable:myButton2">
Loading..<br />
<p:graphicImage name="images/loading_blue.svg" />
</p:blockUI>
Datatable
<p:panel id="blockPanel">
<h:form id="myForm">
<h:panelGrid columns="1" cellpadding="5">
<p:dataTable id="myTable" value="#{modelBean.myList}" var="entry">
<!-- Some data -->
<p:column headerText="Name">
<h:outputText value="#{entry.name}" />
</p:column>
<!-- Does not work -->
<p:column style="text-align: center">
<p:commandButton id="myButton" actionListener="#{bean.method()}" />
</p:column>
<!-- Works -->
<f:facet name="footer">
<p:commandButton id="myButton2" actionListener="#{bean.method()}" />
</f:facet>
</p:dataTable>
</h:panelGrid>
</h:form>
</p:panel>
Why ?
The following workaround did not work for me:
<p:commandLink ... onclick="bui.show()" oncomplete="bui.hide()">
...
<p:blockUI widgetVar="bui" />
As a workaround, I used pe:blockUI:
http://www.primefaces.org/showcase-ext/sections/blockui/blockPage.jsf
What I mean : You don't have any value in your datatable. Put it one, you can create a backingBean return one value and add property value=#{myBean.value}. Also you have data on you datatable ! Test it

PrimeFaces CommandLink does not update components and its action calls just for one time

I have a p:dataTable and contains commandLinks.
<h:form id="defVhclForm">
<p:dataTable id="vehicleTable" var="vhcl" value="#{vehicle.vehicleList}"
scrollable="true" scrollHeight="520">
<p:column id="trackId" label="#{general.vehicleName}" width="120" style="spacing:0;padding-left:10px;border:0px">
<p:commandLink id="editLink" immediate="true" value="#{vhcl.vehicle.vehicleName}" title="#{general.editVehicleInfo}"
action="#{vehicle.vehicleSelected}" style="font-weight:bold; font-size:11px;"
update="#form"/>
<br />
<h:outputText id="vehicleId" value="#{vhcl.vehicle.mtsTrackId}" title="#{general.vehicleId}" style="font-size:10px; color:blue;" />
<br/>
<h:outputText value="#{vhcl.vehicle.vehiclePlate}" id="vehiclePlate" title="#{general.licencePlate}" style="font-size:10px; color:blue"/>
<h:inputHidden value="#{vhcl.vehicle.mtsTrackId}" id="mtsTrackId"/>
</p:column>
</p:dataTable>
<p:tabView id="tabView" styleClass="tableCellHeader" style="align:left">
<p:tab id="vehicleDefinitionTab" title="#{general.vehicle}" styleClass="tableCellHeader">
<h:panelGrid id="mainGrid" columns="2" columnClasses="alignTop, alignTop">
<h:panelGrid id="subGrid" columns="4">
<h:outputLabel id="vhclIdLbl" value="#{general.vehicleId}:"/>
<p:inputText id="vehicleIdTxt" binding="#{vehicle.vehicleIdTxt}" style="width:150px;"/>
<h:outputLabel id="vhclPlateLbl" value="#{general.licencePlate}:"/>
<p:inputText id="vehiclePlateTxt" binding="#{vehicle.vehiclePlateTxt}" style="width:150px;"/>
<h:outputLabel id="vhclNameLbl" value="#{general.vehicleName}:"/>
<p:inputText id="vehicleNameTxt" binding="#{vehicle.vehicleNameTxt}" style="width:150px;"/>
<h:outputLabel id="vhclTypeNameLbl" value="#{general.vehichleType}:"/>
<p:selectOneMenu id="vhclTypeCmb" binding="#{vehicle.vehicleTypeCmb}" styleClass="tableCell" effect="slide" style="width:157px">
<f:selectItem itemLabel="#{general.pleaseSelect}" itemValue="" styleClass="tableCell"/>
<f:selectItems value="#{vehicle.vehicleTypeCmbList}" styleClass="tableCell"/>
</p:selectOneMenu>
</h:panelGrid>
<!-- <p:graphicImage value="#" width="120px" height="80px"/>-->
</h:panelGrid>
</p:tab>
<p:tab id="registrationTab" title="#{general.auth}" styleClass="tableCellHeader">
</p:tab>
</:tabView>
</h:form>
By pressing the commandLink some p:tab should be updated and filled with the related data. Every component is inside the same h:form. Pressing the commandLink does not update the related p:tab s. Also, the commandLink action calls the bean method just for one time. More than one pressing does not call the bean method.
How can I solve this problem?