Primefaces 3.0 DataTable inCell editing , RowEditEvent doesn't retrieve updated field - jsf

I am working on a sample app with primefaces 3 , using datatables incell editing mode. Although when i edit , i see the event.getObjects gives me the object which is not modified.
Changed the property of the object on debug mode, it does update.
So i couldn't figure out why i cant get the edited property.
Below are my eventlistener method and the xhtml;
Any pointers are welcomed
Thanks in advance
EventListener
public void editListener(RowEditEvent event){
System.out.println("EDIT LISTENER");
update((Employer)event.getObject());
}
JSF :
<h:form id="form">
<h1><h:outputText value="List"/></h1>
<p:dataTable value="#{employer.employers}" var="item" paginator="true" rows="10" style="width:300px">
<p:column>
<f:facet name="header">
<h:outputText value="Id"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<p:column headerText="Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{item.name}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{item.name}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Surname"/>
</f:facet>
<h:outputText value="#{item.surname}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Phone"/>
</f:facet>
<h:outputText value="#{item.phone}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{item.email}"/>
</p:column>
<p:column headerText="Options" style="width:50px">
<p:rowEditor />
</p:column>
<p:ajax event="rowEdit" listener="#{employer.editListener}"></p:ajax>
</p:dataTable>
</h:form>

After this...
<p:dataTable value="#{employer.employers}" var="item" paginator="true"
rows="10" style="width:300px">
...put the following:
<p:ajax event="rowEdit" update="#this" listener="#{HandlerClassName.rowEditListener}" />

Related

DataExporter tag - PrimeFaces - page only = "false"

I'm trying to export data from DataTable using DataExporter tag, but, DataExporter is exporting only first page data (page of the print), but I want to export data from all pages.
See below my button code and the screen.
Code:
<p:dataTable id="listaConsulta" rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'jsfcrud_odd_row' : 'jsfcrud_even_row'}" rowIndexVar="rowIx" value="#{funcionarioController.items}" var="item">
<p:column>
<f:facet name="header">
<h:outputText value="Código"/>
</f:facet>
<h:outputText value="#{item.codigo}"/>
</p:column>
<p:column width="25%">
<f:facet name="header">
<h:outputText value="Nome"/>
</f:facet>
<h:outputText value="#{item.nome}"/>
</p:column>
<p:column width="10%">
<f:facet name="header">
<h:outputText value="Cpf"/>
</f:facet>
<h:outputText value="#{item.cpf}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Nascimento"/>
</f:facet>
<h:outputText value="#{item.datanascimento}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column width="25%">
<f:facet name="header">
<h:outputText value="Cargo"/>
</f:facet>
<h:outputText value="#{item.cargo.descricao}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Telefone"/>
</f:facet>
<h:outputText value="#{item.fone}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Celular"/>
</f:facet>
<h:outputText value="#{item.celular}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Ativo"/>
</f:facet>
<h:outputText value="#{item.estaAtivo}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<h:commandLink title="Editar" action="Create?faces-redirect=true&includeViewParams=true">
<f:setPropertyActionListener value="#{item}" target="#{funcionarioController.selected}"/>
<h:graphicImage height="32" value="/image/file_edit.png" />
</h:commandLink>
<h:commandLink title="Ficha Registro" target="_blank" action="#{funcionarioController.gerarRelatorioJasper}">
<f:setPropertyActionListener value="#{item}" target="#{funcionarioController.selected}"/>
<p:graphicImage value="/image/pdf.png" />
</h:commandLink>
</p:column>
</p:dataTable>
</h:panelGroup>
<br />
<p:commandButton ajax="false" immediate="true" action="#{funcionarioController.prepareCreate()}" value="#{bundle.ListFuncionarioCreateLink}"/>
<p:spacer width="10px"/>
<p:commandButton value ="Gerar Excel" ajax="false">
<p:dataExporter type="xls" target="listaConsulta" fileName="dadosFuncionarios" encoding="utf-8" pageOnly="false"/>
</p:commandButton>
Screen:
How do I solve this?
EDIT: I change the code inserting datatable and dataexporter entire code.

The p:commandLink inside the p:datagrid's p:celleditor is not working

The p:commandLink or p:commandButton inside the p:datagrid's celleditor is not working, when i click the commandLink it redirects me to the same page. Inside the celleditor the commandLink cant find its listener, however when i take it outside the celleditor it works perfectly.
<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
<p:dataTable id="project" var="car" value="#{editdeleteview.proj_rec}" rowKey="#{car.id}" selection="#{editdeleteview.selected_rec}" selectionMode="single" editable="true" style="margin-bottom:20px">
<f:facet name="header">
All Projects
</f:facet>
<p:ajax event="rowEdit" listener="#{editdeleteview.onRowEdit}" update=":form:msgs"/>
<p:ajax event="rowEditCancel" listener="#{editdeleteview.onRowCancel}" update=":form:msgs"/>
<p:column headerText="ID">
<h:outputLabel value="#{car.id}" />
</p:column>
<p:column headerText="Title">
<p:commandLink ajax="false" action="#{editdeleteview.openObjects(car)}" ><h:outputText value="#{car.title}" /></p:commandLink>
<p:cellEditor>
<f:facet name="output"><p:commandLink ajax="false" action="#{editdeleteview.openObjects(car)}" ><h:outputText value="#{car.title}" /></p:commandLink></f:facet>
<f:facet name="input"><p:inputText value="#{car.title}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Description">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.description}" /></f:facet>
<f:facet name="input"><p:inputText value="#{car.description}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Insertion Time">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.insertionTimestamp}" /></f:facet>
<f:facet name="input"><p:inputText value="#{car.insertionTimestamp}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Close Time">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.closeTimestamp}" /></f:facet>
<f:facet name="input"><p:inputText value="#{car.closeTimestamp}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px">
<p:rowEditor />
</p:column>
<p:column headerText="Delete">
<p:commandButton id="downloadLink1" value="Delete" ajax="false" class="btn btn-danger" icon="ui-icon-trash" action="#{editdeleteview.delete(car)}">
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
The p:commandLink outside the celleditor under the column title is working perfectly but inside the celleditor the commandLink is not working, the listener in the bean is
public String openObjects(Project p)
{
HttpSession session = SessionUtils.getSession();
session.setAttribute("project_id", p.getId());
session.setAttribute("project_title", p.getTitle());
//session.setAttribute("project_title", "Hamdan");
System.out.println("EditView: "+session.getAttribute("project_title").toString());
return "Objects.xhtml";
}
I have also tried this commandLink in cellEditor doesn't trigger action/actionListener but that didnt worked for me. Any help will be highly appreciated.
just use this and it will work
<f:facet name="output">
<p:commandLink action="#{editdeleteview.openObjects(car)}"
process="#this" immediate="true">
<h:outputText value="#{car.title}" />
<f:setPropertyActionListener
target="#{editdeleteview.selected_rec}" value="#{car}" />
</p:commandLink>
</f:facet>
Try setting immediate="true" on your command link component.
Have a look at this explanation by #BalusC:
Trying to understand immediate="true" skipping inputs when it shouldn't
I'm using primefaces 6.3-SNAPSHOT, this problem still exists, this is how I resolved it :
JSF :
<p:commandLink ajax="false" action="#{editdeleteview.openObjects(car)}" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.title}" />
</f:facet>
<f:facet name="input">
<p:inputText onclick="stopEventPropagation(event)" value="#{car.title}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:commandLink>
JAVASCRIPT :
function stopEventPropagation(event){
event.stopPropagation();
return false;
}

PrimeFaces editable cell doesn't update the value

So I am trying to use a PrimeFaces data table to set data to a list as follows;
<h:form id="frmSalarySupplement">
<p:panel>
<p:dataTable id="tblSalarySupplement"
value="#{salSupplementMB.dataListFromDB}"
var="salSupp"
rowIndexVar="rowSn"
scrollable="true"
rows="10"
paginator="true"
editable="true"
editMode="cell"
rowsPerPageTemplate="10,20,50,100">
<p:ajax event="cellEdit"
listener="#{salSupplementMB.onCellEdit}"
update="#this" />
<p:column headerText="#" escape="false"
style="white-space:pre-line;
word-break:break-all;
width:20px;
text-align:center;">
<h:outputText value="#{rowSn+1}" />
</p:column>
<p:column headerText="Name"
style="white-space:pre-line;
word-break:break-all;
width:250px;">
<h:outputText value="#{salSupp.empId.name}" />
</p:column>
<p:column headerText="Designation"
style="white-space:pre-line;
word-break:break-all;
width:150px;">
<h:outputText value="#{salSupp.empId.designation.designationName}" />
</p:column>
<p:column headerText="Allowance"
style="white-space:pre-line;
word-break:break-all;
width:100px;">
<p:cellEditor>
<f:facet name="input">
<h:inputText value="#{salSupp.allowance}"
style="width:100%" />
</f:facet>
<f:facet name="output">
<h:outputText value="#{salSupp.allowance}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Special
Allowance"
style="white-space:pre-line;
word-break:break-all;
width:100px;">
<p:cellEditor>
<f:facet name="input">
<h:inputText value="#{salSupp.specialAllowance}"
style="width:100%" />
</f:facet>
<f:facet name="output">
<h:outputText value="#{salSupp.specialAllowance}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Transport
Allowance"
style="white-space:pre-line;
word-break:break-all;
width:100px;">
<p:cellEditor>
<f:facet name="input">
<h:inputText value="#{salSupp.transportAllowance}"
style="width:100%" />
</f:facet>
<f:facet name="output">
<h:outputText value="#{salSupp.transportAllowance}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
So I want to be able to save the data I have edited on the cell to set it on the list. When I do the following, I don't get an updated value.
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
}
Can someone suggest what shall I do with it?
Update
Also, can anyone tell me why my table loads multiple times when I edit the value? Maybe that's what's giving me the problem.

Row expansion component submitting form on expansion when roweditor is present

My web page looks like this:
<h:form>
<p:dataTable var="car" value="#{tableBean.carsSmall}">
<f:facet name="header">
Expand rows to see detailed information
</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column style="width:250px">
<f:facet name="header">
Model
</f:facet>
<h:outputText value="#{car.model}" />
</p:column>
<p:column style="width:250px">
<f:facet name="header">
Year
</f:facet>
<h:outputText value="#{car.year}" />
</p:column>
<p:rowExpansion>
<p:fieldset legend="Detail">
<p:dataTable value="#{car.colors}" var="color">
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{color.disable}" />
</f:facet>
<f:facet name="input">
<h:selectBooleanCheckbox value="#{color.disable}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:fieldset>
</p:rowExpansion>
</p:dataTable>
</h:form>
This component is automatically updating the wrong values in database, for example it is setting false for the color.disable property upon just expanding the row.
I am using:
JSF 2.0.9
Primefaces 2.2.1

commandButton does not fire action

<h:form id="main_form">
<p:treeTable var="catalog" value="#{catalogSelectBean.root}" lazy="true" selection="#{myView.selectedCatalogNode}" selectionMode="single">
<p:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{catalog.name}" />
</p:column>
<p:column width="100">
<f:facet name="header">
<h:outputText value="Desc"/>
</f:facet>
<h:outputText value="#{catalog.description}"/>
</p:column>
</p:treeTable>
<!-- The problem commandButton below-->
<p:commandButton action="#{myView.updateProductListForSelectedCatalog}"
update=":main_form:selectProductTable" value="Bring products">
</p:commandButton>
<!-- The problem commandButton above-->
<p:dataTable id="selectProductTable" var="product" value="#{myView.productDataModel}" paginator="true" selection="#{myView.selectedProduct}" >
<f:facet name="header">
Product Selection
</f:facet>
<p:column selectionMode="single" />
<p:column headerText="name">
<h:outputText value="#{product.name}" />
</p:column>
</p:dataTable>
<p:commandButton action="#{myView.setSelectedProductToForm}"
update="main_form"
value="Set">
</p:commandButton>
</h:form>
the problem commandButton does not fire action, if i had selected something in selectproducttable.

Resources