Can't leave editing mode on prime faces roweditor - primefaces

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

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 Dialog doesn't update edit fields

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.

Primefaces ActionListener not fired if h:inputHidden in the datatable

I am using Primefaces 5.1 and have this strange behaviour.
If in my dataTable I have h:inputHidden then mymethod() is not fired.
The method is fired if I remove it.
<p:dataTable id="tablerisorse" value="#{myBean.resources}" var="resource"
rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'oddRow' : 'evenRow'}"
rowIndexVar="rowIndex"
emptyMessage="Empty" headerClass="header">
<p:column>
<h:inputHidden id="id_user" value="#{resource.user}"/>
<f:facet name="header">
<h:outputText value="Surname"/>
</f:facet>
<h:outputText value="#{resource.surname}" />
</p:column>
<p:column>
<p:commandLink id="linkdet" actionListener="#{myBean.mymethod}" ajax="false"onstart="progressbar()" oncomplete="hideprogressbar()">
<p:graphicImage value="images/res.png" style="{border: 0}"></p:graphicImage>
</p:commandLink>
</p:column>
</p:dataTable>
the method is:
public void impegnirisorsa(ActionEvent ae) {
// TODO Auto-generated method stub
HtmlInputHidden uicid_user = (HtmlInputHidden) ae.getComponent().findComponent("id_user");
String id_user = ""+uicid_user .getValue();
System.out.println("id_user"+id_user);
}
I wonder what the problem could be and which workarounds could I use.

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

how to get the database values by using hibernate and how to display that values in a primefaces dataTable?

Here i have some doubts.If you know the answer please post here.
How to get the list of values into database table by using hibernate?
How to display that values into primefaces dataTable?
Here i am posting what i am trying .see below
<p:dataTable id="users" value="#{user.listUsers}" var="user"
sortBy="user.id" rows="10" style="width: 30%">
<p:column>
<f:facet name="header">
<h:outputText value="ID" />
</f:facet>
<h:outputText value="#{user.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{user.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Surname" />
</f:facet>
<h:outputText value="#{user.surName}" />
</p:column>
</p:dataTable>
Here i am finding the answer how to display a table values into primefaces dataTable.
Here i am placing what i am trying code.
<p:dataTable value="#{actions.messages}" var="act">
<p:column style="width:10%;text-align:left" filterBy="#{act.id}" >
<f:facet name="header">
<h:outputText value="ID" id="id" />
</f:facet>
<h:outputText value="#{act.id}" />
</p:column>
<p:column style="width:20%;text-align:left"
sortBy="#{act.action}">
<f:facet name="header">
<h:outputText value="Customer" id="customer" />
</f:facet>
<h:outputText value="#{act.action}" />
</p:column>
<p:column style="width:40%;text-align:left"
sortBy="#{act.scheduled}">
<f:facet name="header">
<h:outputText value="Date" />
</f:facet>
<h:outputText value="#{act.scheduled}" />
</p:column>
<p:column style="width:30%;text-align:left"
sortBy="#{act.status}">
<f:facet name="header">
<h:outputText value="Action" />
</f:facet>
<h:outputText value="#{act.status}" />
</p:column>
</p:dataTable>
Here is the hibernate dao class name called ActionsDao
public class ActionsDao {
public Session session;
public ArrayList<Actions> getActions() {
session = Util.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
try {
#SuppressWarnings("unchecked")
ArrayList<Actions> actionsList = (ArrayList<Actions>) session
.createQuery("from Actions").list();
tx.commit();
boolean found = false;
for (Actions actions : actionsList) {
Actions action = new Actions();
action.setId(actions.getId());
action.setAction(actions.getAction());
action.setActual(actions.getActual());
action.setAssignedBy(actions.getAssignedBy());
action.setAssignedTo(actions.getAssignedTo());
action.setScheduled(actions.getScheduled());
action.setOutcome(actions.getOutcome());
action.setStatus(actions.getStatus());
actionsList.contains(action);
found = true;
}
if (found) {
return actionsList;
} else {
return null;
}
} catch (Exception e) {
System.out.println("Error In getActions() -->" + e.getMessage());
return (null);
} finally {
session.close();
}
}
}
Here is the bean class i am developing name called Actions.
#ManagedBean(name = "actions", eager = true)
#SessionScoped
public class Actions implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
private String action;
private String assignedTo;
private String assignedBy;
private Date scheduled;
private Date actual;
private String outcome;
private String status;
//write here setter & getter methods of the above properties
public ArrayList<Actions> getMessages() {
ActionsDao dao = new ActionsDao();
return dao.getActions();
}
}
you can use the annotations or hbm file that yours choice to map the bean class.
Here i am using only mapping file why because, first i am trying to create annotations but it raised some problems that jar files are some problem.your using the correct jar files that not a problem you can continue the annotations otherwise hbm file is best.