Unable to populate values obtained from ajax call using PrimeFaces - ajax

Hi
I have made an ajax call using primefaces [p:ajax]. The call to the listener was successful and it returned the required values. To update these properties in xhtml, I have checked the DOM source, to find out the exact ID of the column, using which the column or property would be updated. But, in this case the fields are not getting the values.
The code I used in this case is
<p:dataTable id="table1" var="recepit" rowIndexVar="rowIndex" value="#{ReceiptDetailsBean.iterativeList}" scrollable="true" height="120px" styleClass="leftTable">
<p:column style="background-color: #EFF2F9">
<f:facet name="header">
<h:outputText value="SL NO" />
</f:facet>
<h:outputText value="#{rowIndex+1}" />
</p:column>
<p:column >
<f:facet name="header">
<h:outputText value="Buss." />
</f:facet>
<h:selectOneMenu id="selectOneCb" value="#{ReceiptDetailsBean.bussCode}" >
<f:selectItem itemLabel="V_BUSS_CODE" itemValue=""/>
<f:selectItems value="#{ReceiptDetailsBean.rdetails}" var="model" itemLabel="#{model.buss}" itemValue="#{model.buss}"/>
<p:ajax update="mainForm:table1:#{rowIndex}:receiptCode, mainForm:table1:#{rowIndex}:referenceType" actionListener="#{ReceiptDetailsBean.obtainReceiptDatabasedOnBussCode}" event="change"/>
</h:selectOneMenu>
</p:column>
<p:column id="receiptCodeCol">
<f:facet name="header">
<h:outputText value="Receipt Code" />
</f:facet>
<h:inputText value="#{ReceiptDetailsBean.receiptCode}" id="receiptCode" style="font-family: verdana;font-size: 10px;width:80px;height:15px" />
</p:column>
<p:column id="receiptTypeCol">
<f:facet name="header">
<h:outputText value="Ref Type" />
</f:facet>
<h:inputText value="#{ReceiptDetailsBean.receiptType}" id="referenceType" style="font-family: verdana;font-size: 10px;width:80px;height:15px"/>
</p:column>
</p:dataTable>
</div>
</p:tab>
<p:tab title="Print">
</p:tab>
</p:tabView>
</h:form>
The id from the DOM view source was table1:0:receiptCodeHotKey:receiptCode
What would be the problem for the data to not get populated in the field.

I think the source of the problem is your usage of h:form. You don't need to put it around each single input element. Put one h:form around the datatable and then check again the generated ids.
Then it should be something like (example for first row with rowindex 0):
formId:table1:0:receiptCode

Related

Select many checkbox ajax update view on second event

I'm trying to filter a datatable on categories using a select selectManyCheckbox.
The idea is that when a checkbox is clicked, the datatable values are updated.
Now the problem is that the values are updated after selecting a checkbox twice, but this results in a datable with incorret values.
Here is my xhtml page.
<p:layout id="dossierLayout" widgetVar="dossierLayout">
<p:layoutUnit id="categoriesLayoutUnit" position="west"
header="#{msg['dossier.page.layoutWest.header']}">
<p:selectManyCheckbox id="dossierCategories" value="#{dossierBean.dossierFileCategoriesFilter}"
layout="pageDirection" columns="1" converter="dossierCategorieConverter" immediate="true">
<f:selectItems value="#{dossierBean.dossierFileCategorieList}" var="dossierCategorie"
itemLabel="#{dossierCategorie.categorieDescription}"
itemValue="#{dossierCategorie}"/>
<p:ajax listener="#{dossierBean.filterfiles}" update="dossierForm:dossierFiles" />
</p:selectManyCheckbox>
</p:layoutUnit>
<p:layoutUnit id="dossierFilesLayoutUnit" position="center">
<p:dataTable id="dossierFiles" value="#{dossierBean.filteredFiles}" widgetVar="dossierFiles" filteredValue="#{dossierBean.filteredFiles}" var="dossierFile">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="#{msg['dossier.page.datatable.globalSearch.label']}"/>
<p:inputText id="dossierNameFilterInput" value="#{dossierBean.dossierNameFilter}"/>
<p:watermark id="dossierNameFilterInputWaterMark" for="dossierNameFilterInput" value="#{msg['dossier.page.layoutWest.header.watermark']}"/>
</p:outputPanel>
<p:commandButton id="dossierNameFilterSearch" value="#{msg['cmn.search']}" actionListener="#{dossierBean.filterFilesByName}" update="dossierFiles"/>
<p:commandButton id="dossierNameFilerSearchEmpty" value="#{msg['cmn.clear']}" actionListener="#{dossierBean.clearFilterName}" update="dossierFiles"/>
</f:facet>
<p:column id="dossierFileName" filterBy="#{dossierFile.nameDocument}" filterStyle="display: none;" filterMatchMode="contains" headerText="#{msg['dossier.page.datatable.columheader.Name']}">
<h:outputText styleClass="#{dossierFile.dossierFileIcon.docType}"/>
<h:outputText value="#{dossierFile.nameDocument}"/>
</p:column>
<p:column id="dossierFileLastChanged" headerText="#{msg['dossier.page.datatable.columheader.Date']}">
<h:outputText value="#{dossierFile.dateLastChange}"/>
</p:column>
<p:column id="dossierFileUser" headerText="#{msg['dossier.page.datatable.columheader.User']}">
<h:outputText value="#{dossierFile.user}"/>
</p:column>
<p:column id="dossierFileCategorie" headerText="#{msg['dossier.page.datatable.columheader.Categorie']}">
<h:outputText value="#{dossierFile.categorie.categorieDescription}"/>
</p:column>
<p:column id="dossierFileLocation" headerText="#{msg['dossier.page.datatable.columheader.Location']}">
<h:outputText value="#{dossierFile.nameFolder}"/>
</p:column>
</p:dataTable>
</p:layoutUnit>
</p:layout>

p:datatable sort or filter not working

I want to implement a sort and/or filter-function for my datatable, and I have done everything the documentation says.
The problem is, that if I klick on a sort-header or fill in a filter, nothing happens (even the ajax-symbol is not shown to i assume that nothing happens at all).
What can be the problem?
I am using:
templates to show the p:datatable
primefaces 5.1
myfaces bundle 2.2.0-20131222.194304-2575.jar
code:
<ui:define name="content">
<h:form>
<p:dataTable var="user" value="#{logbookProjectMembersBean.projectMembers}"
filterDelay="100" widgetVar="userList" emptyMessage="No ProjectMembers found with given criteria"
filteredValue="#{logbookProjectMembersBean.filteredProjectMembers}" rowStyleClass="#{user.enabled? 'row' : 'inactiveUserRow'}" styleClass="userList">
<f:facet name="header">
<p:outputPanel>
<h:outputText>Overview</h:outputText>
<h:outputText value=" - Search:" />
<p:inputText id="globalFilter" onkeyup="PF('userList').filter()" style="width:150px" placeholder="Enter keyword" />
</p:outputPanel>
</f:facet>
<p:column headerText="Name" filterBy="#{user.name}" filterMatchMode="contains" >
<h:outputText value="#{user.name}" />
</p:column>
<p:column headerText="Surname" filterBy="#{user.surname}" filterMatchMode="contains" >
<h:outputText value="#{user.surname}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>

p:dataTable sorting and filtering error

I've made globalFilter in the header of dataTable and then added sorting to columns. But there is a problem: the columns becoming sortable after the first time I use the filter.
So when the program starts user need to clear already empty filter control and after that can sort data in the table.
Please,could someone recommend me how to solve the problem?
I've made filter like in example on PrimeFaces showcase.
<p:dataTable id="dtParkType"
widgetVar="w_dtParkType"
var="parkTypeWeb"
value="#{parkTypeHolder.data}"
selectionMode= "single"
selection="#{parkTypeController.selectedItem}"
rowKey="#{parkTypeWeb.id}"
emptyMessage="#{msg['common.NoValue']}"
rowStyleClass="#{parkTypeWeb.isDeleted? 'colored' : null}"
filteredValue="#{parkTypeController.filteredData}"
scrollable="true"
scrollRows="27"
paginator="true"
rows="27"
resizableColumns="true">
<f:facet name="header">
<div align="right">
<p:outputPanel>
<h:outputText value="#{msg['edit.Search']}"/>
<p:inputText id="globalFilter"
onkeyup="PF('w_dtParkType').filter()"
style="width:150px;margin-left:5px;"
placeholder="#{msg['common.PlaceHolder.KeyWord']}"/>
</p:outputPanel>
</div>
</f:facet>
<p:ajax event="rowSelect"
listener="#{parkTypeController.onRowSelect}"
update=":rightForm:panelbtnParkType"/>
<p:ajax event="rowDblselect"
listener="#{parkTypeController.callEditForm}"
update=":formEditParkType:pnlEditParkType"/>
<p:ajax event="rowUnselect" update=":rightForm:panelbtnParkType"/>
<p:column filterBy="#{parkTypeWeb.longName}"
filterMatchMode="contains"
filterStyle="display:none"
sortBy="#{parkTypeWeb.longName}">
<f:facet name="header">
<h:outputText value="#{msg['column.Title.Full']}"/>
</f:facet>
<h:outputText value="#{parkTypeWeb.longName}"/>
</p:column>
<p:column filterBy="#{parkTypeWeb.shortName}"
filterMatchMode="contains"
filterStyle="display:none"
sortBy="#{parkTypeWeb.shortName}">
<f:facet name="header">
<h:outputText value="#{msg['column.Title.Short']}"/>
</f:facet>
<h:outputText value="#{parkTypeWeb.shortName}" />
</p:column>
</p:dataTable>

checkbox button in data table

i have checkbox column in datatable, i want to have some ajax code which when i click on the checbox button on the header should check all the checkbox in the rendered data rows of the datatable. I am using primefaces, they have something out of box for this but we don't want to implement it. Please let me know if there is a easy solution using ajax.
As of now we have coded as below but we can go something better than that.
<p:dataTable id="userListTable" value="#{Bean.List}"
var="user" rowClasses="odd even"
<p:column style="width:18px">
<f:facet name="header">
<p:selectBooleanCheckbox
valueChangeListener="#{Controller.toggleCheckBox}"
partialSubmit="true" immediate="true" />
</f:facet>
<p:selectBooleanCheckbox value="#{user.disable}"
disabled="#{user.disable}"
valueChangeListener="#{circleController.enableDisableOkbutton}"
partialSubmit="true" immediate="true" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{labels['circle.userList.name']}" />
</f:facet>
<p:panelGrid styleClass="noBorders">
<p:row>
<p:column rowspan="3" style="width:60px;">
<p:graphicImage
value="#{name}.jpg"
style="width:50px;height:50px" />
</p:column>
<p:column>
<h:outputText value=" " />
<h:outputText value="#{user.firstName}" />
<h:outputText value=" " />
<h:outputText value="#{user.lastName}" />
</p:column>
</p:row>
<p:row>
<h:outputText value="#{user.country}" />
</p:row>
</p:panelGrid>
</p:column>
</p:dataTable>

Ajax call is made but the related fields are updated only after page refresh

I have tried making an ajax call for a selectOneMenu using JSF 2 and primefaces 2.2. The actionListener method is being called. But the columns I specified in the update attribute are not getting updated. When I refersh the page, I could find the updated values. Please help me out in this.
The code I used was
<h:form id="mainForm" prependId="false">
<p>
<p:tabView>
<p:tab title="Receipt">
<p:dataTable id="table1" var="recepit" rowIndexVar="rowIndex" value="#{ReceiptDetailsBean.iterativeList}" scrollable="true" height="120px" styleClass="leftTable">
<p:column style="background-color: #EFF2F9">
<f:facet name="header">
<h:outputText value="SL NO" />
</f:facet>
<h:outputText value="#{rowIndex+1}" />
</p:column>
<p:column >
<f:facet name="header">
<h:outputText value="Buss." />
</f:facet>
<h:selectOneMenu id="selectOneCb4" value="#{ReceiptDetailsBean.bussCode}" >
<f:selectItem itemLabel="V_BUSS_CODE" itemValue=""/>
<f:selectItems value="#{ReceiptDetailsBean.rdetails}" var="model" itemLabel="#{model.buss}" itemValue="#{model.buss}"/>
<p:ajax update="table1:#{rowIndex}:receiptCode, table1:#{rowIndex}:referenceType" actionListener="#{ReceiptDetailsBean.obtainReceiptDatabasedOnBussCode}" event="change"/>
</h:selectOneMenu>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Receipt Code" />
</f:facet>
<h:inputText value="#{ReceiptDetailsBean.receiptCode}" id="receiptCode" style="font-family: verdana;font-size: 10px;width:80px;height:15px" onkeypress="return showForhotKey(event,'#{rowIndex}');"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Ref Type" />
</f:facet>
<h:inputText value="#{ReceiptDetailsBean.receiptType}" id="referenceType" style="font-family: verdana;font-size: 10px;width:80px;height:15px" onkeypress="return showForhotKey(event,'#{rowIndex}');"/>
</p:column>
</p:dataTable>
</p:tab>
<p:tab title="Print">
</p:tab>
Try f:ajax instead of p:ajax and re-render the whole form to get closer to the problem source :
<h:selectOneMenu id="selectOneCb4" value="#{ReceiptDetailsBean.bussCode}" >
<f:selectItem itemLabel="V_BUSS_CODE" itemValue=""/>
<f:selectItems value="#{ReceiptDetailsBean.rdetails}" var="model"
itemLabel="#{model.buss}" itemValue="#{model.buss}"/>
<f:ajax render="#form"
listener="#{ReceiptDetailsBean.obtainReceiptDatabasedOnBussCode}"/>
</h:selectOneMenu>
This should work as stated in my answer to your previous question.
Partial updates of dataTables and ajax updates of dataTables triggered from a component within the dataTable are not working in the 2.2 version of Primefaces. This is a known bug that may have been resolved in version 3.
One suggestion you can try is to use a single form for each dataTable and only update elements from within that one form.

Resources