I'm trying to make editable primefaces datatable. I'm using http://www.primefaces.org/showcase/ui/datatableRowEditing.jsf. All database table data showing up, but then I trying to edit data in a table I'm getting following error:
/index.xhtml #23,90 listener="#{tableBean.onEdit}": Target Unreachable, identifier 'tableBean' resolved to null: javax.el.PropertyNotFoundException: /index.xhtml #23,90 listener="#{tableBean.onEdit}": Target Unreachable, identifier 'tableBean' resolved to null
index.xhtml
<h:head>
<title>index.xhtml</title>
</h:head>
<h:body>
<h:form id="form">
<p:growl id="messages" showDetail="true"/>
<p:dataTable var="u" value="#{logonTest.userList}" id="carList" editable="true">
<f:facet name="header">
In-Cell Editing
</f:facet>
<p:ajax event="rowEdit" listener="#{tableBean.onEdit}" update=":form:messages" />
<p:ajax event="rowEditCancel" listener="#{tableBean.onCancel}" update=":form:messages" />
<p:column headerText="Name" style="width:30%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{u.name}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Surname" style="width:20%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.surname}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{u.surname}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
TableBean.java
public void onEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage(" Edited", ((User) event.getObject()).getName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage(" Cancelled", ((User) event.getObject()).getName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
Related
Cell value is not captured when mouse focus changes
I have a simple datatable that shows the name and income. The cell values are editable. When I update the cell value with a different value and hit "Update" (basically change mouse focus) the new value is not captured. The update method
prints the old value. However, when I press the "tab" key I can see the updated values printed. I am not sure what I am missing
Here is my backing bean:
#PostConstruct
public void init() {
NVPair nvp = new NVPair("xx", 10000);
dataList.add(nvp);
nvp = new NVPair("yy", 20000);
dataList.add(nvp);
}
public void update() {
for (NVPair item : dataList) {
System.out.println("Name: " + item.getName() + " Value: " +
item.getValue());
}
}
Here is the view:
<h:form>
<p:dataTable id="testTable" value="#{testBean.dataList}" var="item"
editable="true" editMode="cell">
<p:ajax event="cellEdit" listener="#{testBean.onCellEdit}"
immediate="true" update="testTable" />
<p:column headerText="Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{item.name}" />
</f:facet>
<f:facet name="input">
<h:outputText value="#{item.name}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Income">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{item.value}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{item.value}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
<p:commandButton action="#{testBean.update}" value="Update" />
</h:form>
When the focus changes, I am expecting that the edited value is captured just like when the tab key is pressed.
<p:dataTable var="item" id="datatable-list" value="#{generalJournalEntryMB.generalJournalEntries}" rows="10"
paginator="true" reflow="true" paginatorPosition="top" rowExpandMode="single"
rendered="#{generalJournalEntryMB.generalJournalEntries.size() > 0}" rowIndexVar="rowIndex"
paginatorTemplate="{CurrentPageReport} {PreviousPageLink} {NextPageLink} " rowKey="#{item.id}"
selectionMode="single" selection="#{generalJournalEntryMB.generalJournalEntry}" widgetVar="datatable-list">
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Id">
<h:outputText value="#{item.id}" />
</p:column>
<p:column headerText="Description">
<h:outputText value="#{item.description}" />
</p:column>
<p:column headerText="Amount">
<h:outputText value="#{item.amount}" />
</p:column>
<p:column headerText="Reference">
<h:outputText value="#{item.reference}" />
</p:column>
<p:column headerText="State">
<h:outputText value="#{item.postingState.value}" />
</p:column>
<p:rowExpansion id="expand" rendered="true">
<p:panelGrid columns="2" columnClasses="label,value" style="width:300px">
<h:outputText value="Id:" />
<h:outputText value="1" />
<h:outputText value="Year" />
<h:outputText value="1983" />
<h:outputText value="Color:" />
<h:outputText value="White" />
<h:outputText value="Price" />
<h:outputText value="#{generalJournalEntryMB.price}" />
</p:panelGrid>
</p:rowExpansion>
<p:ajax event="rowSelect" listener="#{generalJournalEntryMB.rowSelectListener}" update="main:top-menu-bar" />
<p:ajax event="rowToggle" listener="#{generalJournalEntryMB.rowToggleListener}" update="main:top-menu-bar" />
</p:dataTable>
When I expand the row without selecting the row, it show nothing. Currently what am I doing is to first select row and expand it to get desire result.
How we can trigger rowSelect even / ajax call automatically when rowToggle event fire?
You can override primefaces toggleExpansion function so it executes selectRow before
PrimeFaces.widget.DataTable.prototype.toggleExpansion = (function() {
var cached_function = PrimeFaces.widget.DataTable.prototype.toggleExpansion;
return function() {
var row = arguments[0].closest('tr');
if(this.cfg.selectionMode === 'single') {
this.unselectAllRows();
}
if(this.cfg.selectionMode){
this.selectRow(row, false);
}
var result = cached_function.apply(this, arguments);
return result;
};
})();
I am using primefaces 3.4.2 jar. I have a datatable with four columns. In two columns I have a datalist and I want to export text showed by datalist. But when I export it, it shows the following "org.primefaces.component.datalist.DataList#1195cc3" in the pdf and xls file.
<p:dataTable emptyMessage="#{messages['empty.result.set']}" id="searchResult" var="row" value="#{managePessoaJuridica.manageableList}" rows="10" paginator="true" paginatorPosition="top" paginatorAlwaysVisible="false" style="display:#{managePessoaJuridica.manageableList == null? 'none': ''}">
<p:column styleClass="column_icons" exportable="false">
<p:panelGrid columns="#{pessoaJuridicaController.showSelectAction?3:2}">
<p:commandButton id="selectAction" icon="ui-icon-circle-check" title="#{messages['action.select']}" action="#{pessoaJuridicaController.select(row.id)}" immediate="true" process="#this" rendered="#{pessoaJuridicaController.showSelectAction}"/>
<p:commandButton id="editAction" icon="ui-icon-pencil" title="#{messages['action.edit']}" action="#{pessoaJuridicaController.load(row.id)}" immediate="true" process="#this" update="#form"/>
<p:commandButton id="deleteAction" icon="ui-icon-trash" title="#{messages['action.delete']}" action="#{pessoaJuridicaController.delete(row.id)}" immediate="true" process="#this" update="searchResult"
onclick="return confirm('#{messages['confirm.delete.this']} #{messages['pessoa.juridica.view.title']}');" />
</p:panelGrid>
</p:column>
<p:column id="column_nome" sortBy="#{row.nome}" >
<f:facet name="header">
<h:outputText id="columnHeader_nome" value="#{messages['pessoa.nome']}"/>
</f:facet>
<h:outputText id="nome" value="#{row.nome}">
</h:outputText>
</p:column>
<p:column style="width:0px;">
<f:facet name="header">
<h:outputText id="columnHeader_categoriasPessoa" value="#{messages['pessoa.categorias.pessoa']}"/>
</f:facet>
<p:dataList type="definition" id="categoriasPessoa" var="item" value="#{row.categoriasPessoa}" >
<p:column>
<h:outputText id="item_categoriasPessoa" value="#{item}" converter="com.domain.configuracao.crud.CategoriaPessoaJsfConverter"/>
</p:column>
</p:dataList>
</p:column>
<p:column style="width:0px;">
<f:facet name="header">
<h:outputText id="columnHeader_identificacoesPessoa" value="#{messages['pessoa.identificacoes.pessoa']}"/>
</f:facet>
<p:dataList type="definition" id="identificacoesPessoa" var="item" value="#{row.identificacoesPessoa}">
<p:column>
<h:outputText id="item_categoriaIdentificacoes" value="#{pessoaJuridicaController.getCategoriaIdentificacao(item)}" converter="com.domain.configuracao.crud.CategoriaIdentificacaoJsfConverter"/>:
<h:outputText id="item_identificacoesPessoa" value="#{item}" converter="com.domain.configuracao.crud.IdentificacaoPessoaJsfConverter"/>
</p:column>
</p:dataList>
</p:column>
<p:column id="column_ativo" sortBy="#{row.ativo}" >
<f:facet name="header">
<h:outputText id="columnHeader_ativo" value="#{messages['classe.base.cadastro.ativo']}" />
</f:facet>
<h:outputText id="ativo" value="#{row.ativo}" converter="com.BooleanJsfConverter" >
</h:outputText>
</p:column>
<f:facet name="footer">
<p:menuButton value="#{messages['export.action']}" rendered="#{not empty managePessoaJuridica.manageableList}">
<p:menuitem value="#{messages['export.spreadsheet']}" ajax="false">
<p:dataExporter type="xls" target="searchResult" fileName="export" excludeColumns="0" encoding="ISO-8859-1"/>
</p:menuitem>
<p:menuitem value="#{messages['export.pdf']}" ajax="false">
<pe:exporter type="pdf" target="searchResult" fileName="export" excludeColumns="0" encoding="ISO-8859-1"/>
</p:menuitem>
<p:menuitem value="#{messages['export.csv']}" ajax="false">
<p:dataExporter type="csv" target="searchResult" fileName="export" excludeColumns="0" encoding="ISO-8859-1"/>
</p:menuitem>
</p:menuButton>
<p:spacer width="10"/>
<h:outputText value="#{fn:length(managePessoaJuridica.manageableList)} #{messages['records.found']}" rendered="#{not empty managePessoaJuridica.manageableList}"/>
</f:facet>
</p:dataTable>
But when I export it, it shows the following
"org.primefaces.component.datalist.DataList#1195cc3" in the pdf and
xls file.
Obviously, Primefaces's data exporter use the toString() method of an object to print its "value(s)".
Suggestions :
Write a custom exporter (recommended)
Override toString() method of org.primefaces.component.datalist.DataList (not advised)
I have this code that shows a table with a prime faces datatable and a roweditor column. When I click on pencil icon, editable mode is enabled but after that, when I click on check or cancel icon nothing happens, editable mode remains active. I've search a lot about it but I couldn't find response. Listener on backing bean is not called.
This is my code of the view:
<p:dataTable var="vac" value="#{vacDocBean.obl}" id="documentacion" editable="true">
<f:facet name="header">
Table
</f:facet>
<p:ajax event="rowEdit" update="#this" listener="#{vacDocBean.onEditRow(_record)}" />
<p:column headerText="Edad">#{vacuna.inm.e}</p:column>
<p:column headerText="Inm">#{vac.inm.n}</p:column>
<p:column headerText="Fecha aplicacion">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{vac.fechaAplicacion}">
<f:convertDateTime pattern="dd/MM/yyyy"/>
</h:outputText>
</f:facet>
<f:facet name="input">
<p:calendar value="#{vac.fechaAplicacion}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Marca">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{vac.marca}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{vac.marca}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Lote">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{vac.lote}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{vac.lote}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Editar" styleClass="ui-editable-column-options">
<!-- <p:commandLink ajax="true">-->
<p:rowEditor />
<!-- </p:commandLink > -->
</p:column>
<f:facet name="footer">
VacunaciĆ³n documentada
</f:facet>
</p:dataTable>
And the backing bean:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.calendario;
#Named(value="vacDocBean")
#SessionScoped
public class VacDocBean implements Serializable {
private List<Vac> obl;
public VacDocBean() {
obl = new ArrayList<Vac>();
setVac();
Collections.sort(obl);
}
private void setVac()
{
this.obl = new ArrayList(Helper.getObl());
}
public List<Vac> getObl() {
return obl;
}
public void setObligatorias(List<Vac> obl) {
this.obl = obl;
}
public void onEditRow(RowEditEvent e){
System.out.println("Hello");
}
public void onCancel(RowEditEvent e){
System.out.println("Hello 2");
}
}
Thanks!!
Just surround your h:datatable by a h:form tag, since the editable datatable needs it.
To make your listener method work, try that, whithout changing method's signature:
<p:ajax event="rowEdit" listener="#{vacDocBean.onEditRow}" />
I have a form with a panel and two dataTables. The code below has had most of the columns removed to make it easier to follow.
<h:form id="invoiceLookUp">
<p:panel>
<f:facet name="header">
<p:column style="font-weight: bold;">
Invoice Selection Criteria
</p:column>
</f:facet>
<h:outputText value="Seq ID"/>
<p:inputText
id="invoice_header_seq_id" styleClass="field" size="10"
value="#{invoiceBean.invoice_header_seq_id}"
/>
<p:commandButton
update="invoicesTable" value="Look Up"
action="#{invoiceBean.addInvoices()}"
/>
</p:panel>
<p:dataTable
id="invoicesTable" var="invoice" rows="15" lazy="true" selectionMode="single"
value="#{invoiceBean.invoiceList}"
rowKey="#{invoice.invoiceHeader.invoiceHeaderSeqId}"
selection="#{invoiceBean.selectedInvoice}"
>
<p:ajax event="rowSelect" update=":invoiceLookUp:invoiceLinesTable"/>
<f:facet name="header"><h:outputText value="Invoice Headers" /></f:facet>
<p:column sortBy="#{invoice.invoiceHeader.invoiceHeaderSeqId}" id="invoiceSeqId">
<f:facet name="header">
<h:outputText value="Seq ID" title="Invoice Header Seq ID"/>
</f:facet>
<h:outputText value="#{invoice.invoiceHeader.invoiceHeaderSeqId}" />
</p:column>
</p:dataTable>
<p:dataTable
id="invoiceLinesTable" var="invoiceLine" rows="15" lazy="true" selectionMode="single"
value="#{invoiceBean.selectedInvoice.invoiceLines}"
rowKey="#{invoiceLine.invoiceLineSeqId}"
selection="#{invoiceBean.selectedInvoiceLine}"
>
<f:facet name="header"><h:outputText value="Invoice Lines" /></f:facet>
<p:column sortBy="#{invoiceLine.invoiceLineSeqId}" id="invoiceLineSeqId">
<f:facet name="header"><h:outputText value="Line Seq ID"/></f:facet>
<h:outputText value="#{invoiceLine.invoiceLineSeqId}"/>
</p:column>
</p:dataTable>
</h:form>
When you enter a Seq ID and then click Look Up, the table populates as expected. When I select a row in the invoicesTable, I get the following error:
javax.faces.FacesException: Cannot find component with identifier ":invoiceLookUp:invoiceLinesTable" referenced from "form:invoiceLookUp:invoicesTable".
Can anyone tell me what I am doing wrong?