Primefaces Dialog doesn't update edit fields - primefaces

I am doing a page on Primefaces. It has a datatable with single selection, and when i do clic on a button, it shows a Dialog.
If he dialog only shows labels with ouputtext, it works fine, but if I change the labels for inputtexts, the button doesn't update the dialog.
This is mi xhtml file:
<p:dataTable id="deportes" var="deporte" value="#{deporteBean.deportesModel}" rowKey="#{deporte.idDeporte}"
selection="#{deporteBean.deporteActual}" selectionMode="single">
<f:facet name="header">
<h:outputLabel value="#{messages.sports_info_edit}"/>
</f:facet>
<p:column headerText="#{messages.sports_general_name}">
#{deporte.idDeporte}
</p:column>
<p:column headerText="#{messages.sports_general_name}">
#{deporte.nombre}
</p:column>
<p:column headerText="#{messages.sports_general_description}" >
#{deporte.descripcion}
</p:column>
<f:facet name="footer">
<p:commandButton action="#{deporteBean.updateInfo}" actionListener="#{deporteBean.updateInfo}" id="viewButton" value="#{messages.sports_info_viewDetail}" icon="ui-icon-search"
oncomplete="deporteDialog.show()" update=":form:display" />
</f:facet>
</p:dataTable>
<p:dialog id="dialog" header="Detalle del deporte" widgetVar="deporteDialog" resizable="false"
width="400" showEffect="clip" hideEffect="fold" modal="true">
<h:panelGrid id="display" columns="2" cellpadding="4" >
<f:facet name="header">
<h:outputText value="#{deporteBean.deporteActual.nombre}" />
</f:facet>
<h:outputText value="Id" />
<h:outputText value="#{deporteBean.deporteActual.idDeporte}" />
<h:outputText value="Nombre:" />
<h:outputText id="txtNombre" value="#{deporteBean.deporteActual.nombre}" />
<h:outputText value="Descripcion:" />
<h:inputText value="#{deporteBean.deporteActual.descripcion}" />
</h:panelGrid>
<p:commandButton id="aceptarButton" value ="#{messages.sports_info_save}" icon="ui-icon-disk"
action="#{deporteBean.save}" immediate="true"
update=":form:display" oncomplete="deporteDialog.hide()">
</p:commandButton>
</p:dialog>
And this is my Bean (in faces.config.xml his scope is view):
package com.sportsWorld.web.view;
import java.util.ArrayList;
import java.util.List;
import dtorres.gymAdmin.dto.*;
public class DeporteBean {
private List<Deporte> deportes;
private Deporte deporteActual;
private DeporteDataModel deportesModel;
public DeporteBean (){
deportes = new ArrayList<Deporte>();
deportes.add(new Deporte(1,"Tenis de mesa","Velocidad, precisión, concentración y reacción en el deporte más difícil del mundo."));
deportes.add(new Deporte(2,"Fútbol 5","Lo mejor del deporte rey en un espacio pequeño"));
deportes.add(new Deporte(3,"Escalada","Fuerza, concentración y equilibrio se ponen a prueba en este magnfífico deporte para quienes no temen a las alturas"));
deportes.add(new Deporte(4,"Natación","Bla bla bla"));
deportes.add(new Deporte(5,"Gimnasio","Bla bla bla"));
deportes.add(new Deporte(6,"Spinning","Bla bla bla"));
deportes.add(new Deporte(7,"Bolos", "Bla bla bla"));
deporteActual = null;
deportesModel = new DeporteDataModel(deportes);
}
public List<Deporte> getDeportes() {
return deportes;
}
public void setDeportes(List<Deporte> deportes) {
this.deportes = deportes;
}
public Deporte getDeporteActual() {
return deporteActual;
}
public void setDeporteActual(Deporte deporteActual) {
this.deporteActual = deporteActual;
}
public DeporteDataModel getDeportesModel() {
return deportesModel;
}
public void setDeportesModel(DeporteDataModel deportesModel) {
this.deportesModel = deportesModel;
}
public void save(){
System.out.println(deporteActual.getNombre());
}
public void updateInfo(){
System.out.println("Entra a UpdateInfo");
System.out.println("UpdateInfo + " + deporteActual.getNombre());
}
}
The updateInfo method is only for debug purposes, the point is that when I change the line
in the xhtml for it works fine... Thanks a lot!!
Sorry for my english!

I found the solution. The changes in the xhtml file are:
<p:dataTable id="deportes" var="deporte" value="#{deporteBean.deportesModel}" rowKey="#{deporte.idDeporte}" scrollWidth="true"
selection="#{deporteBean.deporteActual}" selectionMode="single"
>
<p:ajax event="rowSelect" listener="#{deporteBean.updateInfo}" update=":form:display"/>
<f:facet name="header">
<h:outputLabel value="#{messages.sports_info_edit}"/>
</f:facet>
<p:column headerText="#{messages.sports_general_name}">
#{deporte.idDeporte}
</p:column>
<p:column headerText="#{messages.sports_general_name}">
#{deporte.nombre}
</p:column>
<p:column headerText="#{messages.sports_general_description}" >
#{deporte.descripcion}
</p:column>
<f:facet name="footer">
<p:commandButton actionListener="#{deporteBean.updateInfo}"
id="viewButton"
value="#{messages.sports_info_viewDetail}"
icon="ui-icon-search"
oncomplete="PF('deporteDialog').show()"
update=":form:display"/>
</f:facet>
</p:dataTable>
Note the <p:ajax> tag.. it seems that the blank input field was updating the value in the bean... whith this ajax action, now i update the field with the bean's value.

Related

In Cell editing does not update value on focus change

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.

Primefaces datatable not editing

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);
}

Primefaces dialog fields not filled after click in CommandLink

I am using Primefaces 3.5 with Weblogic 11. I have a page where a dialog to edit a 'profile' entity ('perfil' in Portuguese) which is called from two places. First from a commandButton to insert a new profile. The second from a dataTable to edit a specific profile. Below, I show the code:
Snippet of XHTML page
<p:fieldset legend="Pesquisa de Perfil">
<p:panelGrid columns="2">
<f:facet name="footer">
<p:commandButton id="btnPesquisar"
actionListener="#{perfilAcessoMB.pesquisar}" value="Pesquisar"
immediate="true" update="pnlPerfis" styleClass="ui-icon-search" />
<p:spacer width="20"></p:spacer>
<!-- OPEN DIALOG TO CREATE A NEW PROFILE -->
<p:commandButton id="btnIncluir" value="Incluir"
update="dlgPerfil" immediate="true"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao(null)}"
oncomplete="dlgPerfil.show();">
</p:commandButton>
</f:facet>
</p:panelGrid>
</p:fieldset>
<br />
<p:outputPanel id="pnlPerfis" layout="block">
<p:fieldset id="resultadoPesquisa" legend="Resultado da Pesquisa"
rendered="#{not empty perfilAcessoMB.perfis}">
<p:dataTable id="tblPerfis" value="#{perfilAcessoMB.perfis}"
var="perfil" emptyMessage="Nenhum perfil encontrado.">
<p:column headerText="Nome do Perfil">
<h:outputText value="#{perfil.nome}"></h:outputText>
</p:column>
<p:column headerText="Descrição do Perfil">
<h:outputText value="#{perfil.descricao}"></h:outputText>
</p:column>
<p:column headerText="Situação do Perfil"
style="text-align: center; width: 100px;">
<h:outputText value="Ativo" rendered="#{perfil.situacao}" />
<h:outputText value="Inativo" rendered="#{not perfil.situacao}" />
</p:column>
<p:column headerText="Editar"
style="text-align: center; width: 50px;">
<!-- OPEN DIALOG TO EDIT A NEW PROFILE -->
<p:commandLink id="lnkEditar" immediate="true"
title="Editar Perfil" update=":formPrincipal:dlgPerfil :formPrincipal:pnlPerfilEdicao"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao(perfil)}"
oncomplete="dlgPerfil.show();">
<h:outputText value="Editar" />
</p:commandLink>
</p:column>
<p:column headerText="Excluir"
style="text-align: center; width: 50px;">
</p:column>
</p:dataTable>
</p:fieldset>
</p:outputPanel>
<p:dialog id="dlgPerfil" widgetVar="dlgPerfil" resizable="false"
closable="true" modal="true" closeOnEscape="true"
header="#{(empty perfilAcessoMB.perfil)? 'Incluir': 'Editar'} Perfil">
<h:outputText value="#{perfilAcessoMB.perfil}"></h:outputText>
<h:panelGroup id="pnlPerfilEdicao" layout="block">
<p:fieldset legend="Dados do Perfil">
<p:panelGrid columns="2">
<h:outputLabel id="lblNomePerfilEdicao" value="Nome do Perfil"
for="txtNomePerfilEdicao" />
<p:inputText id="txtNomePerfilEdicao" required="true"
requiredMessage="É obrigatório preencher o campo Nome do Perfil."
value="#{perfilAcessoMB.perfil.nome}" maxlength="20" size="20"></p:inputText>
<h:outputLabel id="lblDescricaoPerfilEdicao"
value="Descrição do Perfil" for="txtDescricaoPerfilEdicao" />
<p:inputText id="txtDescricaoPerfilEdicao" required="true"
requiredMessage="É obrigatório preencher o campo Descrição do Perfil."
value="#{perfilAcessoMB.perfil.descricao}" maxlength="20"
size="20"></p:inputText>
<h:outputLabel id="lblSituacaoPerfilEdicao" value="Situação"
for="selSituacaoPerfilEdicao" />
<p:selectOneMenu id="selSituacaoPerfilEdicao"
value="#{perfilAcessoMB.perfil.situacao}">
<f:selectItems value="#{perfilAcessoMB.situacoesEdicao}" />
</p:selectOneMenu>
</p:panelGrid>
</p:fieldset>
<br />
<p:fieldset legend="Permissões">
<p:pickList id="pickFuncoes" value="#{perfilAcessoMB.funcoes}"
var="funcao" itemValue="#{funcao}"
itemLabel="#{funcao.descricao}" required="true"
requiredMessage="É obrigatório associar ao menos uma funcionalidade ao perfil."
converter="funcaoConverter" />
<p:column>#{funcao.descricao}</p:column>
</p:fieldset>
<p:panelGrid columns="2">
<p:commandButton id="btnSalvarPerfil" value="Salvar"
actionListener="#{perfilAcessoMB.salvar}"
oncomplete="if(args && !args.validationFailed) dlgPerfil.hide();" />
<p:commandButton id="btnCancelarPerfil" value="Cancelar"
immediate="true" onclick="dlgPerfil.hide();" />
</p:panelGrid>
</h:panelGroup>
</p:dialog>
MangedBean (perfilAcessoMB)
#ManagedBean
#ViewScoped
public class PerfilAcessoMB extends BaseMB {
private PerfilAcessoORM perfil;
private List<PerfilAcessoORM> perfis;
private String nomePerfil;
private Boolean situacao;
private DualListModel<FuncaoORM> funcoes;
private SelectItem[] situacoesPesquisa = new SelectItem[] {
new SelectItem(null, "Todos"), SELECT_ITEM_ATIVO,
SELECT_ITEM_INATIVO };
private SelectItem[] situacoesEdicao = new SelectItem[] {
SELECT_ITEM_ATIVO, SELECT_ITEM_INATIVO };
private FuncaoORM funcaoA = new FuncaoORM(1L, "FUNÇÃO A"), //
funcaoB = new FuncaoORM(2L, "B Function"), //
funcaoC = new FuncaoORM(10L, "Se Funssaum");
public void abrirDialogoEdicao(PerfilAcessoORM p) {
this.perfil = (p == null)? new PerfilAcessoORM(): p;
System.out.println("PerfilAcessoMB.onAbrirDialogoEdicao(): "
+ this.perfil);
List<FuncaoORM> funcoesDisponiveis = new ArrayList<FuncaoORM>(
Arrays.asList(funcaoA, funcaoB, funcaoC));
// Remove from funcoesDisponiveis those whose are present in perfil.
if (this.perfil.getFuncoes() == null) {
this.funcoes = new DualListModel<FuncaoORM>(funcoesDisponiveis,
Lists.<FuncaoORM> newArrayList());
} else {
funcoesDisponiveis.removeAll(this.perfil.getFuncoes());
this.funcoes = new DualListModel<FuncaoORM>(funcoesDisponiveis,
this.perfil.getFuncoes());
}
}
// Getters & Setters
}
PerfilAcessoORM (Profile) Entity
public class PerfilAcessoORM {
private Long id;
private String nome;
private String descricao;
private Boolean situacao = null;
private List<FuncaoORM> funcoes;
// Getters & Setters
}
FuncaoORM Entity:
public class FuncaoORM {
private Long id;
public String descricao;
// Getters & Setters
}
What is my problem? Apparently, when I want insert a new Profile, all seems OK. However, when I click to edit an existent profile to open the dialog, although the outputText and pickList are correctly filled, the inputText's and selectOneMenu are not.
Looking for solutions, I found here a suggestion to use appendToBody="true" in dialog. When I tried, the inputText's and selectOneMenu are correctly filled. However, the validation is not working as waited. When I click to save it is showed a message indicating that pickList is not filled, even if it is really filled. Actually, even if inputText's are not filled, there is no message about these inputTexts although they are required.
Another alternative would be use <f:setPropertyActionListener> inside commandLink:
<!-- OPEN DIALOG TO CREATE A NEW PROFILE -->
<p:commandButton id="btnIncluir" value="Incluir"
update="dlgPerfil" immediate="true"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao}"
oncomplete="dlgPerfil.show();">
<f:setPropertyActionListener target="#{perfilAcessoMB.perfil}" value="#{null}"/>
</p:commandButton>
<!-- OPEN DIALOG TO EDIT A NEW PROFILE -->
<p:commandLink id="lnkEditar" immediate="true"
title="Editar Perfil" update=":formPrincipal:dlgPerfil :formPrincipal:pnlPerfilEdicao"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao}"
oncomplete="dlgPerfil.show();">
<f:setPropertyActionListener target="#{perfilAcessoMB.perfil}" value="#{perfil}"/>
<h:outputText value="Editar" />
</p:commandLink>
The actionListener method would changed to:
public void abrirDialogoEdicao() {
if(this.perfil == null) {
this.perfil = new PerfilAcessoORM();
}
System.out.println("PerfilAcessoMB.onAbrirDialogoEdicao(): "
+ this.perfil);
// The rest remains the same ...
}
Now, when I click to create a new perfil, although in actionListener method the perfil attribute is filled, I got a NullPointerException when the dialog is renderized. It is like first is called perfilAcessoMB.setPerfil(), after the dialog is opened and finally actionListener method. On the other hand, if I click to edit an existent profile, I return to initial situation.
Therefore, I am lost, without idea how to solve this issue.
Thanks,
Rafael Afonso
The solution was incredible simple: just added process="#this" to both commandButtons.
<!-- OPEN DIALOG TO EDIT A NEW PROFILE -->
<p:commandLink id="lnkEditar" immediate="true"
title="#{msg['titulo.edicao']}" process="#this"
update=":formPrincipal:dlgPerfil"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao(perfil)}"
oncomplete="dlgPerfil.show();">
<h:outputText value="#{msg['titulo.edicao']}" />
</p:commandLink>

Export your dataTable to Excel and PDF using Primefaces

I use POI & Itext jar to export Data to PDF or Excel file, I would like to generate a report that contain the data from datatable, but here is what I got as result
http://hpics.li/3653d83
As you see, fields contain variable not the data from datatable.
I would like that file containe data like id, name, email... Please any suggestion
This is my FormateurController.java
package com.controller;
import com.dao.FormateurDao;
import com.dao.InterfaceFormateur;
import com.lowagie.text.BadElementException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.model.Formateur;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.servlet.ServletContext;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
/**
*
* #author Ucf
*/
#ManagedBean
#SessionScoped
public class FormateurController {
private Formateur formateur;
private DataModel listFormateurs;
private Formateur selectedFormateur;
private Formateur[] selectedFormateurs;
private List<Formateur> filteredFormateurs;
public Formateur getFormateurs() {
if(this.formateur == null){
this.formateur = new Formateur();
}
return formateur;
}
public void setFormateurs(Formateur formateur) {
this.formateur = formateur;
}
public DataModel getListFormateurs() {
List<Formateur> lista = new FormateurDao().list();
listFormateurs = new ListDataModel(lista);
return listFormateurs;
}
public void preparerajouterFormateur(ActionEvent actionEvent){
formateur = new Formateur();
}
public void preparermodifierFormateur(ActionEvent actionEvent){
formateur = (Formateur)(listFormateurs.getRowData());
}
public void ajouter(ActionEvent actionEvent){
InterfaceFormateur dao = new FormateurDao();
dao.enregistrer(formateur);
}
public void modifier(ActionEvent actionEvent){
InterfaceFormateur dao = new FormateurDao();
dao.actualiser(formateur);
}
public String exclure(){
Formateur employers = (Formateur)(listFormateurs.getRowData());
InterfaceFormateur dao = new FormateurDao();
dao.supprimer(employers);
return "index";
}
public Formateur getSelectedFormateur() {
return selectedFormateur;
}
public void setSelectedFormateur(Formateur selectedFormateur) {
this.selectedFormateur = selectedFormateur;
}
public List<Formateur> getFilteredFormateurs() {
return filteredFormateurs;
}
public void setFilteredFormateurs(List<Formateur> filteredFormateurs) {
this.filteredFormateurs = filteredFormateurs;
}
public Formateur[] getSelectedFormateurs() {
return selectedFormateurs;
}
public void setSelectedFormateurs(Formateur[] selectedFormateurs) {
this.selectedFormateurs = selectedFormateurs;
}
public void postProcessXLS(Object document) {
HSSFWorkbook wb = (HSSFWorkbook) document;
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow header = sheet.getRow(0);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
for(int i=0; i < header.getPhysicalNumberOfCells();i++) {
HSSFCell cell = header.getCell(i);
cell.setCellStyle(cellStyle);
}
}
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
Document pdf = (Document) document;
pdf.open();
pdf.setPageSize(PageSize.A4);
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator + "ACTUS-0-740-econocom-logo.gif";
pdf.add(Image.getInstance(logo));
}
public String redirectFormateur(){
return "ModifierFournisseur.xhtml";
}
}
this is my index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Gestion de réservation pour une formation</title>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="150">
<center> <h1>Gestion de réservation pour une formation</h1></center>
</p:layoutUnit>
<p:layoutUnit position="west" size="200" rendered="true" collapsible="true" resizable="true" closable="true" header="menu">
<h:form>
<p:commandLink value="Nouveau formateur" actionListener="#{formateurController.preparerajouterFormateur(actionEvent)}" onclick="dlgFormateur.show();" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:form id="form">
<p:dialog widgetVar="dlgFormateur" resizable="false" height="400" width="450" header="Ajout formateur" position="center">
<p:panelGrid columns="2">
<h:outputText value="nom"/>
<p:inputText id="adresse2" value="#{formateurController.formateurs.adresse}"/>
<h:outputText value="cin"/>
<p:inputText id="cin2" value="#{formateurController.formateurs.cin}"/>
<h:outputText value="email"/>
<p:inputText id="email2" value="#{formateurController.formateurs.email}"/>
<h:outputText value="nom"/>
<p:inputText id="nom2" value="#{formateurController.formateurs.nom}"/>
<h:outputText value="prenom"/>
<p:inputText id="prenom2" value="#{formateurController.formateurs.prenom}"/>
<h:outputText value="pseudo"/>
<p:inputText id="pseudo2" value="#{formateurController.formateurs.pseudo}"/>
<h:outputText value="sexe"/>
<p:inputText id="sexe2" value="#{formateurController.formateurs.sexe}"/>
<h:outputText value="telephone"/>
<p:inputText id="telephone2" value="#{formateurController.formateurs.telephone}"/>
<p:commandButton value="enregistrer" id="eng" actionListener="#{formateurController.ajouter(actionEvent)}" update="dataformateur" oncomplete="dlgFormateur.hide()"/>
</p:panelGrid>
</p:dialog>
<p:dataTable id="dataformateur" value="#{formateurController.listFormateurs}" var="formateur" rowKey="#{formateur.formateurId}" paginator="true" rows="10" selection="#{formateurController.selectedFormateurs}" selectionMode="multiple" filteredValue="#{formateurController.filteredFormateurs}" rowsPerPageTemplate="5,10,20,30">
<p:ajax event="rowSelect" update=":form:display" oncomplete="formateurDialog.show()" />
<f:facet name="header">
List of Formateurs
</f:facet>
<p:column headerText="Id" sortBy="#{formateur.formateurId}" filterBy="#{formateur.formateurId}" id="id_formateur">
#{formateur.formateurId}
</p:column>
<p:column headerText="Adresse" sortBy="#{formateur.adresse}" filterBy="#{formateur.adresse}" id="adresse">
#{formateur.adresse}
</p:column>
<p:column headerText="CIN" sortBy="#{formateur.cin}" filterBy="#{formateur.cin}" id="cin">
#{formateur.cin}
</p:column>
<p:column headerText="Email" sortBy="#{formateur.email}" filterBy="#{formateur.email}" id="email">
#{formateur.email}
</p:column>
<p:column headerText="Nom" sortBy="#{formateur.nom}" filterBy="#{formateur.nom}" id="nom">
#{formateur.nom}
</p:column>
<p:column headerText="Prenom" sortBy="#{formateur.prenom}" filterBy="#{formateur.prenom}" id="prenom">
#{formateur.prenom}
</p:column>
<p:column headerText="Pseudo" sortBy="#{formateur.pseudo}" filterBy="#{formateur.pseudo}" id="pseudo">
#{formateur.pseudo}
</p:column>
<p:column headerText="Sexe" sortBy="#{formateur.sexe}" filterBy="#{formateur.sexe}" id="sexe">
#{formateur.sexe}
</p:column>
<p:column headerText="Telephone" sortBy="#{formateur.telephone}" filterBy="#{formateur.telephone}" id="telephone">
#{formateur.telephone}
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Excluir" />
</f:facet>
<p:commandLink value="Excluir" action="#{formateurController.exclure()}" onclick="if(!confirm('Existe déjà #{formateur.nom}?'))return false;" update ="dataformateur"/>
</p:column>
</p:dataTable>
<h:panelGrid columns="2">
<p:panel header="Export All Data">
<h:commandLink>
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="dataformateur" fileName="formateurs" postProcessor="#{formateurController.postProcessXLS}" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="dataformateur" fileName="formateurs"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/csv.png" />
<p:dataExporter type="csv" target="formateur" fileName="formateurs" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/xml.png" />
<p:dataExporter type="xml" target="formateur" fileName="formateurs" />
</h:commandLink>
</p:panel>
<p:panel header="Export Page Data">
<h:commandLink>
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="formateur" fileName="formateurs" pageOnly="true"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="formateur" fileName="formateurs" pageOnly="true"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/csv.png" />
<p:dataExporter type="csv" target="formateur" fileName="formateurs" pageOnly="true"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/xml.png" />
<p:dataExporter type="xml" target="formateur" fileName="formateurs" pageOnly="true"/>
</h:commandLink>
</p:panel>
</h:panelGrid>
<p:dialog header="Formateur Detail" widgetVar="formateurDialog" resizable="false"
width="300" showEffect="explode" hideEffect="explode">
<p:dataList id="display"
value="#{formateurController.selectedFormateurs}"
var="selectedFormateur" type="definition">
Id: #{selectedFormateur.formateurId}, Adresse: #{selectedFormateur.adresse}
</p:dataList>
</p:dialog>
</h:form>
</p:layoutUnit>
</p:layout>
</h:body>
</html>
I'd be grateful for your feedback.
It's because you're printing the variables and not an outputtext with the VALUE of the fields. Took me two hours to figure it out.
Instead of
#{formateur.adresse}
write
<h:outputText value="#{formateur.adresse}" />
You should instantiate Formateur in the beginning itself like:
private Formateur formateur = new Formateur();
When you call its getter, you are checking if formateur is null, but it has not been initialized yet. That might be the problem as far as I understand. I am not sure if you can check if an object is null if it has not even been created/initialized. So, maybe try initializing it in the declarataion itself OR try removing the condition where you check if it is null.

Can't leave editing mode on prime faces roweditor

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}" />