i'm having trouble updating an object in a datatable even thow it works just fine with other objects using incell edeting:
i have an object called Audit wich includes an object Statu and an object utilisateur like this
private int id;
private Statu statu;
private Utilisateur utilisateur;
private OrganismeAudite organismeAudite;
private String date;
private String personneRencontre;
in the datatable i do :
<p:dataTable var="car" value="#{AuditBean.listAudit}" id="carList" editable="true">
<p:ajax event="rowEdit" update="#this"
listener="#{AuditBean.rowEditListener}" />
<f:facet name="header">
Modification
</f:facet>
<p:column headerText="ID" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.id}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{car.id}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Date" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.date}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{car.date}" style="width:100%" label="Year" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Personne Rencontre" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.personneRencontre}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{car.personneRencontre}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Responsable Audit">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.utilisateur.nom}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu id="idUtilisateur" value="#{car.utilisateur.idutilisateur}">
<f:selectItems value="#{UtilisateurBean.listUtilsa}"
var="utilisateur" itemLabel="#{car.utilisateur.nom}"
itemValue="#{car.utilisateur.idutilisateur}" />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Statut Audit" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.statu.libelle}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu id="idStatut" value="#{car.statu.id}">
<f:selectItems var="statu" value="#{StatusBeane.listSta}"
itemLabel="#{car.statu.libelle}"
itemValue="#{car.statu.id}" />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Organisme Audité" style="width:125px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.organismeAudite.nom}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu id="idOrganisme" value="#{AuditBean.idOrganisme}">
<f:selectItems var="orgStA" value="#{OrganismeAuditeBean.listOrga}" />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options" style="width:50px">
<p:rowEditor />
</p:column>
</p:dataTable>
the responsable audit column is updated just fine but it doesn't work in the statu audit column. They'r both a one to many relation (i'm using hibernate and spring ioc)
int the bean the rowlistener goes like this :
public void rowEditListener(RowEditEvent ev) {
try {
Audit userEdit = (Audit) ev.getObject();
Utilisateur u= new Utilisateur();
Statu sta=new Statu();
System.out.println(userEdit.getStatu().getId());
// getUserEJB().save(userEdit);
System.out.println(userEdit.getDate() + " - " + userEdit.getId()+" - "+userEdit.getUtilisateur().getIdutilisateur()+" - "+userEdit.getStatu().getLibelle());
resp.update(userEdit);
} catch (Exception e) {
e.printStackTrace();
}
}
now whene i choose a statu the userEdit.getStatu().getLibelle() shows me the original statu not the one that i have chosen from the list, but if i click on the check incon it only saves one value every time wich is the seconde element(statu)!!!!!!!!!!!!!!!!!
i don't know what i'm doing wrong
thanks in advance :)
Related
I'm trying to get a value from an inputtext typed inside a datatable column and update an outputtext from other column with the multiply of this inputtext value and other inputtext value. My problem is that I can't get the value typed when ajax is called because I'm getting the previous value from the field that receive the value (gasto.valor), not the current value typed. This is my code:
XHTML
<p:dataTable binding="#{cadastroContasBean.dataTable}" var="gasto"
value="#{cadastroContasBean.listaGasto}" scrollable="true"
scrollHeight="150" editable="true" editMode="cell" id="Tabela"
widgetVar="wTabela">
<p:column headerText="Nome">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{gasto.nome}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{gasto.nome}" style="width:96%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Quantidade">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{gasto.quantidade}" />
</f:facet>
<f:facet name="input">
<p:inputText id="inputQtd" value="#{gasto.quantidade}"
style="width:96%" onkeydown="MascaraNumero()"
onkeyup="MascaraNumero()">
<p:ajax event="blur" render="outputVT" listener="#{cadastroContasBean.atualizaVT}" execute="inputQtd" process="#this" immediate="true"/>
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Valor">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{gasto.valor}">
<f:convertNumber currencySymbol="R$" type="currency" />
</h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText id="inputValor" value="#{gasto.valor}"
style="width:96%" onkeyup="mascara(this, valor)"
onkeydown="mascara(this, valor)">
<f:convertNumber pattern="#,##0.00"></f:convertNumber>
<f:validator validatorId="MoedaValidator" />
<p:ajax event="blur" render="outputVT" listener="#{cadastroContasBean.atualizaVT}" execute="inputValor" process="#this" immediate="true" >
</p:ajax>
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Valor Total" id="vt">
<h:outputText id="outputVT" value="#{gasto.valorTotal}">
<f:convertNumber currencySymbol="R$" type="currency" />
</h:outputText>
</p:column>
</p:dataTable>
MB
public void atualizaVT(AjaxBehaviorEvent event) {
Gastos gastoDataTableAtual = ((Gastos)dataTable.getRowData());
if(!event.getComponent().getId().equals("inputQtd")){
BigDecimal valorAtual = (BigDecimal)((UIOutput)event.getSource()).getValue();
gastoDataTableAtual.setValorTotal(valorAtual.multiply(new BigDecimal(((Gastos)dataTable.getRowData()).getQuantidade())));
Iterator<Gastos> gastosAsIterator = listaGasto.iterator();
while (gastosAsIterator.hasNext()){
Gastos it = gastosAsIterator.next();
int id = 0;
if(it.getId() == gastoDataTableAtual.getId()){
//listaGasto.get(id).setValor(gastoDataTableAtual.getValor());
listaGasto.get(id).setValorTotal(gastoDataTableAtual.getValorTotal());
((Gastos)dataTable.getRowData()).setValorTotal(gastoDataTableAtual.getValorTotal());
break;
}
id++;
}
}else{
Integer valorAtual = (Integer)((UIOutput)event.getSource()).getValue();
gastoDataTableAtual.setValorTotal(((Gastos)dataTable.getRowData()).getValor().multiply(new BigDecimal(valorAtual)));
Iterator<Gastos> gastosAsIterator = listaGasto.iterator();
int id = 0;
while (gastosAsIterator.hasNext()){
Gastos it = gastosAsIterator.next();
if(it.getId() == gastoDataTableAtual.getId()){
//listaGasto.get(id).setQuantidade(gastoDataTableAtual.getQuantidade());
listaGasto.get(id).setValorTotal(gastoDataTableAtual.getValorTotal());
((Gastos)dataTable.getRowData()).setValorTotal(gastoDataTableAtual.getValorTotal());
break;
}
id++;
}
I understant that ajax event "blur" is called before "gasto.valor" is changed, but when I change the ajax event to "change" the method "atualizaVT" is not called. How can I get this value?
"change" event is not an AjaxBehaviorEvent.
Try to implement atualizaVT without argument
In this way:
public void atualizaVT(){
This should work.
In my cell edit event in my backing bean, if the cell value is changed I want to update the value of another column as well of the datatable. The value is getting correctly set in my list object but is not getting reflected in my datatable. I tried updating using the datatable using RequestContext as well, but still the list is not getting refreshed. What am I doing wrong? Should I call any row event for this change?
Code snippet :
Bean
#Named("editView")
#ViewScoped
public class EditTableView implements Serializable {
private List<Cars> carList;
private List<String> brands;
#PostConstruct
public void init() {
brands = new ArrayList<String>();
brands.add("BMW");
brands.add( "Mercedes");
brands.add("Volvo");
brands.add("Audi");
brands.add("Renault");
brands.add("Fiat");
brands.add("Volkswagen");
brands.add("Honda");
brands.add("Jaguar");
brands.add( "Ford");
brands.add("Maruti Suzuki");
carList = new ArrayList<Cars>();
modifiedList = new ArrayList<Cars>();
Cars car =new Cars();
car.setCarId(1);
car.setBrand("BMW");
car.setColor("Grey");
car.setModelNumber("2323");
car.setSelfDriven("Y");
car.setYear("1980");
car.setStatus("");
carList.add(car);
}
public void onCellEdit(CellEditEvent event) {
int rowIndex = event.getRowIndex();
Cars car = null;
LOGGER.info("Car Edited"+rowIndex);
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
DataTable carTable = (DataTable) event.getSource();
String index = carTable.getClientId(FacesContext.getCurrentInstance());
LOGGER.info(index);
if(newValue != null && !newValue.equals(oldValue)) {
LOGGER.info("Cell Changed Old: " + oldValue + ", New:" + newValue);
car=carList.get(rowIndex);
carList.get(event.getRowIndex()).setStatus("Changed");
modifiedList.add(car);
}
}
}
xhtml
<h:form id="cellEditForm">
<p:dataTable id="cars" var="car" value="#{editView.carList}"
editable="true" editMode="cell" widgetVar="cellCars">
<f:facet name="header">Cell Editing</f:facet>
<p:ajax event="cellEdit" listener="#{editView.onCellEdit}"
update=":cellEditForm:cars" />
<p:column headerText="Id">
#{car.carId}
</p:column>
<p:column headerText="Model Name" style="background-color:yellow">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.modelNumber}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{car.modelNumber}"
style="width:96%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Year" style="background-color:yellow">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.year}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{car.year}" style="width:96%" label="Year" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Brand" style="background-color:yellow">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.brand}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{car.brand}" style="width:100%">
<f:selectItems value="#{editView.brands}" var="man"
itemLabel="#{man}" itemValue="#{man}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Self Driven" style="background-color:yellow">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.selfDriven}" />
</f:facet>
<f:facet name="input">
<p:inplace>
<p:inputText value="#{car.selfDriven}" />
</p:inplace>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Color" style="background-color:yellow">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.color}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{car.color}" style="width:96%" label="Color" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<h:outputText value="#{car.status}" id="statusLabel"></h:outputText>
</p:column>
</p:dataTable>
</h:form>
I used jquery eventually. Got the index of the updated row and called jquery function from my bean.
RequestContext requestContext = RequestContext.getCurrentInstance();
String call = "updateCell(" + event.getRowIndex() + ")";
requestContext.execute(call);
Jquery code
function updateCell(i) {
var index = "cellEditForm:cars:"+i+":statusLabel";
document.getElementById(index).innerHTML="Changed";
}
OmniFaces has a great util for this, called 'Ajax'
A StackOverflow post about this shows how to use it: How to use OmniFaces Ajax.updateColumn() or Ajax.updateRow() via p:ajax
Update form not table or put table in panel and update panel.
to be safe
<h:form id="cellEditForm">
<p:panel id="something" styleclass="pero">
<p:dataTable id="cars
update="#(.pero)"
be sure to put id on panel because class update will search for that id and use it. This solution is because i don't know rest of the code and it is one that will work on any code.
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?
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
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.