<p:selectBooleanButton ajax is not firing the method - ajax

I want to open a dataTable list when I click to selectBooleanButton. There is an ajax listener in selectBooleanButton but it is not entering the method on debug node. Here are the codes.
<h:form id="form">
<p:growl id="growl" showDetail="true" sticky="true" />
<h:outputText value="" />
<h3>#{res['ko.yetkiVerme.yetkiVerme.title']}</h3>
<p:dataTable id="uyeListe" var="uy" rowKey="#{uy.kullaniciadi}"
value="#{yetkiVermeBean.uyelerList}" paginator="true" rows="5"
rowsPerPageTemplate="5,10,15" paginatorPosition="bottom"
selection="#{yetkiVermeBean.selectedEntity}" selectionMode="single">
<f:facet name="header">
<h:outputText value="#{res['ko.yetkiVerme.uyeListe.title']}" />
</f:facet>
<p:column filterBy="#{uy.kullaniciadi}" sortBy="#{uy.kullaniciadi}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="#{res['ko.yetkiVerme.uyeListe.userName']}" />
</f:facet>
<h:outputText value="#{uy.kullaniciadi}" />
</p:column>
<p:column filterBy="#{uy.ad}" sortBy="#{uy.ad}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="#{res['ko.yetkiVerme.uyeListe.name']}" />
</f:facet>
<h:outputText value="#{uy.ad}" />
</p:column>
<p:column filterBy="#{uy.soyad}" sortBy="#{uy.soyad}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="#{res['ko.yetkiVerme.uyeListe.surName']}" />
</f:facet>
<h:outputText value="#{uy.soyad}" />
</p:column>
</p:dataTable>
<p:spacer height="20" />
<p:selectBooleanButton id="viewYetkilerButton"
offLabel="#{res['ko.yetkiVerme.uyeListe.unshowAuthorize']}"
value="#{!yetkiVermeBean.isRendered}"
onIcon="#{res['ko.plusIcon']}" offIcon="#{res['ko.minusIcon']}"
onLabel="#{res['ko.yetkiVerme.uyeListe.showAuthorize']}">
<p:ajax listener="#{yetkiVermeBean.checkSelectionforYetkiVer}"
update="viewYetkilerButton"/>
</p:selectBooleanButton>
<p:outputPanel id="listePanel">
<p:dataTable id="uyeListe2" var="uy" rowKey="#{uy.kullaniciadi}"
rendered="#{yetkiVermeBean.isRendered}"
value="#{yetkiVermeBean.uyelerList}" paginator="true" rows="5"
rowsPerPageTemplate="5,10,15" paginatorPosition="bottom"
selectionMode="single">
<f:facet name="header">
<h:outputText value="#{res['ko.yetkiVerme.uyeListe.title']}" />
</f:facet>
<p:column filterBy="#{uy.kullaniciadi}"
sortBy="#{uy.kullaniciadi}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="#{res['ko.yetkiVerme.uyeListe.userName']}" />
</f:facet>
<h:outputText value="#{uy.kullaniciadi}" />
</p:column>
<p:column filterBy="#{uy.ad}" sortBy="#{uy.ad}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="#{res['ko.yetkiVerme.uyeListe.name']}" />
</f:facet>
<h:outputText value="#{uy.ad}" />
</p:column>
</p:dataTable>
</p:outputPanel>
</h:form>
</ui:define>
And this is my ajax method.
public void checkSelectionforYetkiVer() {
RequestContext context = RequestContext.getCurrentInstance();
isRendered = Boolean.TRUE;
context.update("form:listePanel");
}
What is in leave out?

Related

How to validate a List<Object> in a Primefaces dataTable - JSF

I have a dataTable for Phone something like :
<p:dataTable value="#{billingInfoBean.billingProfile.payer.phones}" var="phone" id="payerPhoneTable">
<p:column>
<f:facet name="header">
<h:outputText value="Type" />
</f:facet>
<p:selectOneMenu value="#{phone.type}">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{backOfficeLookupClient.allPhoneTypes}" />
</p:selectOneMenu>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Area Code" />
</f:facet>
<h:inputText value="#{phone.areaCode}" size="3" maxlength="3" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Exchange" />
</f:facet>
<h:inputText value="#{phone.exchange}" size="3" maxlength="3" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Local" />
</f:facet>
<h:inputText value="#{phone.local}" size="4" maxlength="4" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Extension" />
</f:facet>
<h:inputText value="#{phone.extension}" size="5" maxlength="5" />
</p:column>
</p:dataTable>
I am trying to use custom validation using the object Phone. I need to call a Phone Validation service which takes these column values as inputs. Can I make use of <f:validator> here in this case?, If yes, how ?
You could attach to the dataTable a validator listener
<f:event type="postValidate" listener="#{bean.customValidation}"/>
And validate the phone object in your bean
public void customValidation(ComponentSystemEvent event) {
...
}
Then iterate through all dataTable childrens and validate each one.
Here ther's a good tutorial to start with.
This omnifaces tag solved my problem :
http://showcase.omnifaces.org/validators/validateMultiple

why does the p:dialog not submit values to bean

I have a small jsf/primefaces application with a datgrid that shows (order) items.
Now I want to add items during a dialog.
I open the dialog with a button click. - works
I want to submit the values from the dialog to the bean and update the datagrid.
If I use a default value (not from the dialog) it works. The item get shown in the datagrid and the dialog get closed. That means.
-addItem Function works
-update works
But if I want to add the values from the dialog I get a null Pointer Exception. So my values will not set in the bean.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:fieldset legend="Positionen" toggleable="true" toggleSpeed="500" styleClass="mbsFieldSet">
<h:form id="form_positions">
<p:growl id="messages" showDetail="true" />
<!-- Add position mask -->
<!-- Button to open the open position mask -->
<p:commandButton id="btOpenAddPositionMask" value="Position via Dialog" onclick="dlg.show();">
</p:commandButton>
<p:dataTable var="banfPosition" value="#{banfPositionBean.lsBanfPositions}"
id="tableBanfPositions" editable="true" >
<f:facet name="header">Positionen</f:facet>
<!-- AJAX Events for editing position values -->
<p:ajax event="rowEdit" listener="#{banfPositionBean.onEdit}"
update=":form_positions:messages"/>
<p:ajax event="rowEditCancel" listener="#{banfPositionBean.onCancel}"
update=":form_positions:tableBanfPositions" />
<p:column headerText="Menge" style="width:50px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{banfPosition.amount}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{banfPosition.amount}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Matr. / Lager-Nr." style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{banfPosition.stockNumber}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{banfPosition.stockNumber}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Artikel" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{banfPosition.article}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{banfPosition.article}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Preis/Einheit" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{banfPosition.price}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{banfPosition.price}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Gesamtpreis" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{banfPosition.sum}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{banfPosition.sum}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Etat-Nr" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{banfPosition.etat}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{banfPosition.etat}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Anlagen-Nr" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{banfPosition.complex}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{banfPosition.complex}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Ändern" style="width:20px; text-align:center">
<p:rowEditor />
</p:column>
<p:column headerText="Löschen" style="width:20px; text-align:center" >
<p:commandButton id="deletePos" actionListener="#{banfPositionBean.deletePos(banfPosition)}"
update=":form_positions:tableBanfPositions" ajax="true" icon="ui-icon ui-icon-close" iconPos="center"
title="Löscht den Eintrag in dieser Zeile." />
</p:column>
</p:dataTable>
</h:form>
</p:fieldset>
<p:dialog header="Neue Position hinzufügen" widgetVar="dlg"
resizable="false">
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel value="Artikel:" />
<p:selectOneMenu id="selectArticleForPosition"
value="#{banfPositionBean.selectedArticle}" var="art"
panelStyle="width:150px" style="width:260px" effect="fade"
filterMatchMode="starts" filter="true">
<f:selectItems value="#{dataBean.lsArticle}" var="article"
itemLabel="#{article.name}" itemValue="#{article}" />
<p:column>
#{art.id} - #{art.name}
</p:column>
</p:selectOneMenu>
</h:panelGrid>
<p:commandButton id="btAddPosition" value="Position einfügen"
actionListener="#{banfPositionBean.addPos()}"
update=":form_positions:tableBanfPositions" oncomplete="dlg.hide();"
ajax="true" process="#all" type="submit">
</p:commandButton>
</p:dialog>
</ui:composition>
I try it with the h:form-Tag as it is shown on http://www.primefaces.org/showcase/ui/dialogForm.jsf But If I add this.
<p:dialog header="Neue Position hinzufügen" widgetVar="dlg"
resizable="false">
<h:form id="form_dialog">
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel value="Artikel:" />
<p:selectOneMenu id="selectArticleForPosition"
value="#{banfPositionBean.selectedArticle}" var="art"
panelStyle="width:150px" style="width:260px" effect="fade"
filterMatchMode="starts" filter="true">
<f:selectItems value="#{dataBean.lsArticle}" var="article"
itemLabel="#{article.name}" itemValue="#{article}" />
<p:column>
#{art.id} - #{art.name}
</p:column>
</p:selectOneMenu>
</h:panelGrid>
<p:commandButton id="btAddPosition" value="Position einfügen"
actionListener="#{banfPositionBean.addPos()}"
update=":form_positions:tableBanfPositions" oncomplete="dlg.hide();"
ajax="true" process="#all" type="submit">
</p:commandButton>
</h:form>
</p:dialog>
the page get reloaded but my bean will not be called either.
Do anyone have an idea what i am doing wrong?
Thanks for help.
-------------------------------------------
*EDIT*
-------------------------------------------
I try it with an p:inputText instead of an selectOneMenu an the bean gets called.
<p:dialog header="Neue Position hinzufügen" widgetVar="dlg"
resizable="false" appendToBody="true">
<h:form id="form_dialog">
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel for="inputTxt" value="Artikel:" />
<p:inputText id="inputTxt" value="#{banfPositionBean.testStr}"></p:inputText>
</h:panelGrid>
<p:commandButton id="btAddPosition" value="Position einfügen"
actionListener="#{banfPositionBean.addPos()}"
update=":form_positions:tableBanfPositions" oncomplete="dlg.hide();">
</p:commandButton>
</h:form>
</p:dialog>
So I just need to find out why it will not work for the selectOneMenu.
First I don't know what is a type of property selectedArticle, I guess it is the same type as article (in itemValue) attribute. You should define converter or on the other hand you should bind value of selectOneMenu to be the same type as article.id, and set itemValue to #{article.id}.

ajax is not updating a component situated in another <ui:define

Hi i have a command link so when click it i action="#{projectAdminisrationMB.showGroups(userObj)}" a fieldset will be rendred <p:fieldset legend="Manage User Groups" id="manageUserGroupsFS" rendered="#{projectAdminisrationMB.manageUserGroupsFSFlag}">
when the fieldset was in the same <ui:define name="body"> everything works but when i put it in a separated ui:define it will not be rendered.
Here's the code :
<ui:define name="body">
<h:form id="manageProjeUFform">
<div class="right">
<p:growl id="growl" showDetail="true" sticky="true" />
<br/><br/><br/><br/>
<h:panelGrid columns="2" cellpadding="10">
<p:column>
<p:fieldset legend=" Users ">
<h:panelGrid columns="2" cellpadding="10">
<p:dataTable border="1" value="#{projectAdminisrationMB.projectUsersList}"
id="projectUserDt"
var="userObj"
rowKey="#{userObj.name}"
selection="#{projectAdminisrationMB.selectedExistingProjectUser}"
selectionMode="single"
rowIndexVar="rowIndex"
binding="#{table1}">
<p:column id="column1">
<f:facet name="header">
<h:outputText value="Login"></h:outputText>
</f:facet>
<h:outputText value="#{userObj.name}"/>
</p:column>
<p:column id="column2">
<f:facet name="header">
<h:outputText value="Entire Name"></h:outputText>
</f:facet>
<h:outputText value="#{userObj.lastName}"></h:outputText>
<h:outputText value="#{userObj.firstName}"></h:outputText>
</p:column>
<p:column id="column5">
<f:facet name="header">
<h:outputText value="Groups"></h:outputText>
</f:facet>
<p:commandLink id="manageUG" title="Manage User Groups" style="margin-right:5px" update=":rightContentform:manageUserGroupsFS" action="#{projectAdminisrationMB.showGroups(userObj)}" ajax="true">
<h:graphicImage value="../images/cssImg/manage-groups-icon.png" />
<f:setPropertyActionListener target="#{projectAdminisrationMB.selectedUserRow}" value="#{userObj}" />
<f:setPropertyActionListener target="#{projectAdminisrationMB.selectedUserRow.dbRowIndex}" value="#{table.rowIndex}" />
</p:commandLink>
</p:column>
<f:facet name="footer">
<p:commandButton id="addProjectUserdlg" value=" Add " onclick="dlg1.show()" />
<p:commandButton id="deleteProjectUserdlg" value=" Delete " onclick="confirmation.show()"/>
</f:facet>
</p:dataTable>
</h:panelGrid>
</p:fieldset>
</div>
</h:form>
</ui:define>
<h:panelGrid columns="3">
<h:panelGrid id="display" header="User Detail" columns="2" cellpadding="4">
<f:facet name="header">
<p:graphicImage value="/images/users/user.png"/>
</f:facet>
<h:outputText value="Login:" />
<h:outputText value="#{projectAdminisrationMB.selectedUserRow.lastName}" />
<h:outputText value="Name:" />
<h:outputText value="#{projectAdminisrationMB.selectedUserRow.lastName}" />
<h:outputText value="First Name:" />
<h:outputText value="#{projectAdminisrationMB.selectedUserRow.firstName}" />
<h:outputText value="Email:" />
<h:outputText value="#{projectAdminisrationMB.selectedUserRow.email}" />
<h:outputText value="Phone:" />
<h:outputText value="#{projectAdminisrationMB.selectedUserRow.phoneNumber}" />
</h:panelGrid>
<p:pickList id="pickList" value="#{projectAdminisrationMB.selectedUserGroups}" var="group"
itemLabel="#{group}" itemValue="#{group}" converter="groupConverter" >
<f:facet name="sourceCaption">Belong To</f:facet>
<f:facet name="targetCaption">Exclude From</f:facet>
<p:column style="width:25%">
<p:graphicImage value="/images/group/#{group.name}.gif" />
</p:column>
<p:column style="width:75%;">
#{group.name}
</p:column>
<p:ajax event="transfer" listener="#{projectAdminisrationMB.onTransferGroup}" update=":manageProjeUFform:growl" />
</p:pickList>
<p:commandButton id="saveGroupsBtn" value="Save" update=":manageProjeUFform:growl" actionListener="#{projectAdminisrationMB.saveUserGroupsModif}"/>
</h:panelGrid>
</p:fieldset>
</h:form>
</ui:define>
Any help will be appreciated .
here's the solution enjoy it :)
<p:commandLink id="manageUG" title="Manage User Groups" style="margin-right:5px"
update="#all" action="#{projectAdminisrationMB.showGroups(userObj)}" ajax="true">
<h:graphicImage value="../images/cssImg/manage-groups-icon.png" />
<f:setPropertyActionListener target="#{projectAdminisrationMB.selectedUserRow}" value="#{userObj}" />
<f:setPropertyActionListener target="#{projectAdminisrationMB.selectedUserRow.dbRowIndex}" value="#{table.rowIndex}" />
</p:commandLink>
i used #all to update the ui define section that's it

How to update other components when rowsPerPage or page changes in <p:dataTable>

I would like to update a component showing data related to the info displayed in the current page of a primefaces dataTable but I couldn't find any info about intercepting ajax events like
onRowsPerPageChange or onPageChanged.
Is there any way to do that?
Using primefaces 3.0.M3 and Glassfish 3.1
Here is my table. The component I want to update is another dataTable inside the footer of the first one:
<p:dataTable id="timbrature_dt"
value="#{timbratureMBean.dataModel}"
paginator="true"
rows="12"
lazy="true"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="6,12,24"
currentPageReportTemplate="#{msgs.pagina} {currentPage} #{msgs.of} {totalPages}"
var="tdett"
widgetVar="ttable"
selection="#{timbratureMBean.selezione}"
selectionMode="single">
<p:ajax event="rowSelect" listener="#{timbratureMBean.onRowSelect}"
update="display :timbrature_dt:giustificativi_dt"
oncomplete="timbDialog.show()" />
<f:facet name="header">
<h:panelGrid columns="1" columnClasses="columnclass-noborders">
<p:outputPanel>
<h:outputText value="#{msgs.dal}: " />
<p:calendar value="#{timbratureMBean.daData}"
pattern="dd/MM/yyyy"
locale="it"
showButtonPanel="true"
navigator="true"
mindate="01/01/2003"
maxdate="#{timbratureMBean.oggi}">
<p:ajax event="dateSelect" listener="#{timbratureMBean.dataChangeListener}"
update="timbrature_dt :timbrature_dt:giustificativi_dt" />
</p:calendar>
<h:outputText value=" #{msgs.al}: " />
<p:calendar value="#{timbratureMBean.aData}"
pattern="dd/MM/yyyy"
locale="it"
showButtonPanel="true"
navigator="true"
mindate="01/01/2003"
maxdate="#{timbratureMBean.oggi}">
<p:ajax event="dateSelect" listener="#{timbratureMBean.dataChangeListener}"
update="timbrature_dt :timbrature_dt:giustificativi_dt" />
</p:calendar>
</p:outputPanel>
<h:outputText value="#{msgs.timbrature}"/>
</h:panelGrid>
</f:facet>
<p:column>
<f:facet name="header">
#{msgs.data_comp}
</f:facet>
<amp:outputData value="#{tdett.sDtComp}"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.data_reale}
</f:facet>
<amp:outputData value="#{tdett.sDtTimb}"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.terminale}
</f:facet>
<h:outputText value="#{tdett.nrTer}"/>
</p:column>
<p:column filterBy="#{tdett.eU}" filterOptions="#{timbratureMBean.euOptionList}">
<f:facet name="header">
#{msgs.verso}
</f:facet>
<h:panelGroup>
<h:outputText value="#{msgs.entrata}" rendered="#{tdett.eU == 'E'}"/>
<h:outputText value="#{msgs.uscita}" rendered="#{tdett.eU == 'U'}"/>
</h:panelGroup>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.ora_valida}
</f:facet>
<h:outputText value="#{tdett.oraValida}"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.ora_reale}
</f:facet>
<h:outputText value="#{tdett.oraReale}"/>
</p:column>
<f:facet name="footer">
<p:dataTable id="giustificativi_dt"
value="#{timbratureMBean.dataList}"
var="gius"
widgetVar="gtable">
<f:facet name="header">
<h:panelGrid columns="1" columnClasses="columnclass-noborders">
<h:outputText value="#{msgs.giustificativi}"/>
</h:panelGrid>
</f:facet>
<p:column>
<f:facet name="header">
#{msgs.voce}
</f:facet>
<h:outputText value="#{gius.voce}"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.dal}
</f:facet>
<amp:outputData value="#{gius.sDtIGius}"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.al}
</f:facet>
<amp:outputData value="#{gius.sDtFGius}"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.nr_giorni}
</f:facet>
<h:outputText value="#{gius.nrGiorni}"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.ora_inizio}
</f:facet>
<amp:outputNvl value="#{gius.oraIGius}" nullval="-"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.ora_fine}
</f:facet>
<amp:outputNvl value="#{gius.oraFGius}" nullval="-"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.nr_ore}
</f:facet>
<amp:outputNvl value="#{gius.nrOre}" nullval="-"/>
</p:column>
<p:column>
<f:facet name="header">
#{msgs.nr_minuti}
</f:facet>
<amp:outputNvl value="#{gius.nrMinuti}" nullval="-"/>
</p:column>
</p:dataTable>
</f:facet>
</p:dataTable>
<p:dialog header="Info" widgetVar="timbDialog" resizable="false"
width="200" showEffect="clip" hideEffect="clip">
<h:panelGrid id="display" columns="2" cellpadding="4">
<h:outputText value="Data:" style="font-weight: bold"/>
<amp:outputData value="#{timbratureMBean.selezione.sDtComp}" />
<h:outputText value="Pausa pranzo ridotta: " style="font-weight: bold"/>
<h:outputText value="#{timbratureMBean.gestPausaPranzo}" />
<h:outputText value="Timbratura non allineata: " style="font-weight: bold"/>
<h:outputText value="#{timbratureMBean.timbNonAllineate}" />
</h:panelGrid>
</p:dialog>
Hou,
there is an event for changing a page, see here
http://cagataycivici.wordpress.com/2011/06/10/datatable-hooks/
<p:datatable paginator="true" rows="10" value="#{bean.items}" var="item">
<p:ajax event="page" listener="#{bean.onPaginate}" update="othercomponents" oncomplete="alert('done')"... />
...
though I am still looking for an event for onChangeRows
but, my current problem is only storing user choices, in fact that page event solves storing both on what page I am and how many rows are selected. If onPaginate implements in this way:
public void onPaginate(PageEvent event){
logger.info("I am on page:"+event.getPage());
logger.info("Rows per page set:"+((org.primefaces.component.datatable.DataTable)event.getSource()).getRows());
}
You can see what page you are on and how many rows are selected. And this event is triggered both when you change a page or change how many rows shown.
My solution is using Primefaces 5.2.x.
I found a pretty easy way to implement this, one of the problems I had with udik's solution was that when the onPaginate() method was called, it didn't have the newest selected value.
So here's what I did to make sure you always had the latest value and could save/load it to the database or a cookie or something (we save to a cookie).
<p:dataTable
.....
paginator="true"
paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="Total records: {totalRecords}, showing page {currentPage} of {totalPages}"
rowsPerPageTemplate="25,50,100"
rows="#{controller.rowsPerPage}"
.....
>
.....
<p:ajax event="page" oncomplete="rowsPerPageUpdate()" />
.....
</p:dataTable>
<p:remoteCommand name="rowsPerPageUpdate" actionListener="#{controller.onPaginate}" />
and then our controller looks like this:
#Dependent
#Named
public class TableController implements Serializable {
private String rowsPerPage = "25"; //default value
.....
public void onPaginate() {
//save to the cookie
}
.....
}
Basically the magic happens in the remoteCommand, which will fire after the ajax event to insure that controller.rowsPerPage has been properly updated.

primefaces datatable filtering

I use the car example from primefaces site, but it works only one time and do not refresh values after onkeyup event. Can somebody help me?:) TOM
Code which I use(from tutorial):
<p:dataTable var="car" value="#{tableBean.carsSmall}"
emptyMessage="No cars found with given criteria"
widgetVar="carsTable">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="carsTable.filter()" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column filterBy="#{car.model}"
headerText="Model" footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{car.model}" />
</p:column>
<p:column filterBy="#{car.year}"
headerText="Year" footerText="startsWith">
<h:outputText value="#{car.year}" />
</p:column>
<p:column filterBy="#{car.manufacturer}"
headerText="Manufacturer" footerText="exact"
filterOptions="#{tableBean.manufacturerOptions}"
filterMatchMode="exact">
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column filterBy="#{car.color}"
headerText="Color" footerText="endsWith" filterMatchMode="endsWith">
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>
</h:form>
and TableBean exactly like this in tut

Resources