dataTable rowEditor does not work - Please Help.

UI Components for JSF
jlferreira
Posts: 43
Joined: 16 Nov 2010, 17:52

26 Nov 2010, 19:03

Hello,
Do any of you could help me to implement a "rowEditor?
I'm trying to implement "rowEditor" in a dataTable, but without success.
When you press the pencil icon in a row, the input fields become editable, but when I change the value and confirm the change, nothing happens.
This is the xhtml page code:

Code: Select all

<!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://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core">
	<f:view>
			<ui:insert name="padraocabecalho">
				<ui:include src="/resources/templates/padraocabecalhopfp.xhtml" />
			</ui:insert>
		
		<h:form id="form_gruposseguranca">
			<p:growl id="growl" showDetail="true" sticky="true" rendered="true"/>
		    <p:dataTable id="segGruposList" var="c" value="#{segGruposController.lseggrupos}"
		    				rowEditListener="#{segGruposController.dataTableOnRowEdit}">
				<f:facet name="header">  
					Grupos de Segurança   
				</f:facet>  

				<p:column headerText="Código" style="width:350px">  
					<p:cellEditor>  
						<f:facet name="output">  
							<h:outputText value="#{c.segGruposCodigo}" />  
						</f:facet>  
						<f:facet name="input">  
							<h:inputText value="#{c.segGruposCodigo}" disabled="true" readonly="true" style="width:100%"/>  
						</f:facet>  
					</p:cellEditor>  
				</p:column>  

				<p:column headerText="Descrição" style="width:350px">  
					<p:cellEditor>  
						<f:facet name="output">  
							<h:outputText value="#{c.segGruposDescri}" />  
						</f:facet>  
						<f:facet name="input">  
							<h:inputText value="#{c.segGruposDescri}" style="width:100%"/>
						</f:facet>
					</p:cellEditor>  
				</p:column>  
				<p:column headerText="Opções">
					<p:rowEditor />  
				</p:column>  
		    </p:dataTable>
		</h:form>
	</f:view>
</html>
This is the SegGruposlController.java code:

Code: Select all

package br.com.sitic.sitic.seguranca.action;

import java.io.Serializable;
import java.util.List;

import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.persistence.EntityManager;

import org.primefaces.event.RowEditEvent;

import br.com.sitic.sitic.sistema.model.SegGrupos;

public class SegGruposController implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private SegGrupos seggrupos;
	private List<SegGrupos>	lseggrupos;
	private Integer 		seggruposcodigo;
	@SuppressWarnings("rawtypes")
	private DataModel model;
	private EntityManager	em;

	public SegGruposController(){
		seggrupos = new SegGrupos();
		
	}
	
	public Integer getSeggruposcodigo() {
		return seggruposcodigo;
		
	}

	public void setSeggruposcodigo(Integer seggruposcodigo) {
		this.seggruposcodigo = seggruposcodigo;
	}
	public void setLseggrupos(List<SegGrupos> lseggrupos) {
		this.lseggrupos = lseggrupos;
	}
	@SuppressWarnings("unchecked")
	public List<SegGrupos> getLseggrupos(){
		SegGruposDAO seggruposdao = new SegGruposDAO();
		lseggrupos = seggruposdao.exibir();
		return lseggrupos;
	}

	public SegGrupos getSeggrupos(){
		if (seggruposcodigo != null) {
			seggrupos = em.find(SegGrupos.class, seggruposcodigo);
		}
		if (seggrupos == null) {
			seggrupos = new SegGrupos();
		}
		return seggrupos;
	}
	
	public void setSeggrupos(SegGrupos seggrupos){
		this.seggrupos = seggrupos;
	}
	
	public void dataTableOnRowEdit(RowEditEvent event){
		SegGruposDAO seggruposdao = new SegGruposDAO();
		seggrupos = (SegGrupos) event.getObject();
		System.out.println("Codigo: "+seggrupos.getSegGruposCodigo()+", Descrição: "+seggrupos.getSegGruposDescri());
		seggruposdao.alterar(seggrupos);
	}
	
	public String adicionar() {
		seggrupos = new SegGrupos();
		return "grupossegurancaform";
	}

	public String deletar(){
		SegGruposDAO seggruposdao = new SegGruposDAO();
		seggruposdao.deletar(seggrupos);
		return "Listar";
	}

	public String salvar() {
		SegGruposDAO seggruposdao = new SegGruposDAO();
		if (getSeggrupos().getSegGruposCodigo() == null) {
			seggruposdao.adicinar(seggrupos);
		}
		else {
			seggruposdao.alterar(seggrupos);
		}
		return "Salvar";
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public DataModel getTodos(){
		SegGruposDAO seggruposdao = new SegGruposDAO();
		model = new ListDataModel(seggruposdao.exibir());
		return model;
	}
		
	public int getCount(){
		SegGruposDAO seggruposdao = new SegGruposDAO();
		return seggruposdao.exibir().size();
	}

}
This is the SegGruposDAO.java:

Code: Select all

package br.com.sitic.sitic.seguranca.action;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import br.com.sitic.sitic.sistema.action.DAO;
import br.com.sitic.sitic.sistema.model.SegGrupos;

public class SegGruposDAO extends DAO{
	public void adicinar(SegGrupos seggrupos){
		EntityManager em = getEntityManager();
		EntityTransaction trans = em.getTransaction();
		trans.begin();
		try {
			em.persist(seggrupos);
			trans.commit();
		} catch (RuntimeException e) {
			trans.rollback();
		}
	}
	public void alterar(SegGrupos seggrupos){
		EntityManager em = getEntityManager();
		EntityTransaction trans = em.getTransaction();
		trans.begin();
		try {
			seggrupos = em.merge(seggrupos);
			trans.commit();
		} catch (RuntimeException e) {
			trans.rollback();
		}
	}
	public void deletar(SegGrupos seggrupos){
		EntityManager em = getEntityManager();
		try{
			em.getTransaction().begin();
			if (seggrupos.getSegGruposCodigo() == null){
				em.persist(seggrupos);
			} else{
				seggrupos = em.merge(seggrupos);
				em.remove(seggrupos);
				em.getTransaction().commit();
			}
		} catch (Exception e) {
			em.getTransaction().rollback();
		}
	}

	@SuppressWarnings("rawtypes")
	public List exibir(){
		EntityManager em = getEntityManager();
		try{
			Query q = em.createQuery("select c from SegGrupos as c");
			return q.getResultList();
		}
		finally{
			em.close();
		}
	}
}
This is the faces-config.xml:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">
	<managed-bean>
		<description>Este é o bean responsável pela validação do usuário no login.</description>
		<managed-bean-name>loginBean</managed-bean-name>
		<managed-bean-class>br.com.sitic.sitic.sistema.factory.backing.LoginBean</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
	<managed-bean>
		<managed-bean-name>segGruposController</managed-bean-name>
		<managed-bean-class>br.com.sitic.sitic.seguranca.action.SegGruposController</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
	
	<navigation-rule>
		<from-view-id>/index.xhtml</from-view-id>
		<navigation-case>
			<from-outcome>principal</from-outcome>
			<to-view-id>/principal.xhtml</to-view-id>
		</navigation-case>
	</navigation-rule>
</faces-config>
Eclipse Helios.
JSF-2.0 (Mojarra 2.1.0-b11).
GlassFish 3.1.
PrimeFaces 2.2.1
EclipseLink 2.1.x - EclipseLink 2.1.x.
PostgreSQL 9.0

jlferreira
Posts: 43
Joined: 16 Nov 2010, 17:52

26 Nov 2010, 20:32

Another information.
In the code that I posted you can see in SegGruposController.java a System.out.println line.
When I run this page I can see in the console monitor the result of this print.
The printed results are the values of line that I choose to modify, but the values before the change that I made.
For example:
If I click in pencil icon, modify the segCadGruposDescri input field, and click in confirm icon, the result printed is the value of segCadGruposDescri before the changes.

Again, I appreciate any help.

Thanks,
Jefferson.
Eclipse Helios.
JSF-2.0 (Mojarra 2.1.0-b11).
GlassFish 3.1.
PrimeFaces 2.2.1
EclipseLink 2.1.x - EclipseLink 2.1.x.
PostgreSQL 9.0

grenadadoc
Posts: 34
Joined: 23 Mar 2010, 15:58

26 Nov 2010, 23:25

I'm certainly no expert, but first thing I noticed was in your XHTML code w/ regards to inputText, you have readOnly=true and disabled=true.

You might try removing those two attributes and see what happens.

If that doesn't work, someone with more experience and knowledge than I will have to chime in...
PF 3.5
NetBeans 7.2.1
GF 3.1.2
Mojarra 2.1.17

jlferreira
Posts: 43
Joined: 16 Nov 2010, 17:52

27 Nov 2010, 05:20

I really wanna disable the first input field.
The second is enabled.
Even without disabling it, the update didn't work.
Thanks for post.
Any another idea?
Eclipse Helios.
JSF-2.0 (Mojarra 2.1.0-b11).
GlassFish 3.1.
PrimeFaces 2.2.1
EclipseLink 2.1.x - EclipseLink 2.1.x.
PostgreSQL 9.0

jlferreira
Posts: 43
Joined: 16 Nov 2010, 17:52

27 Nov 2010, 15:14

This problem was also reported by bumble.bee at:
http://primefaces.prime.com.tr/forum/vi ... =roweditor
I'm using the lastest PrimeFaces version available.
Do this problem continues?
May Someone help me?
Thanks all.
Eclipse Helios.
JSF-2.0 (Mojarra 2.1.0-b11).
GlassFish 3.1.
PrimeFaces 2.2.1
EclipseLink 2.1.x - EclipseLink 2.1.x.
PostgreSQL 9.0

jlferreira
Posts: 43
Joined: 16 Nov 2010, 17:52

28 Nov 2010, 23:10

Someone may help me?
Eclipse Helios.
JSF-2.0 (Mojarra 2.1.0-b11).
GlassFish 3.1.
PrimeFaces 2.2.1
EclipseLink 2.1.x - EclipseLink 2.1.x.
PostgreSQL 9.0

jlferreira
Posts: 43
Joined: 16 Nov 2010, 17:52

29 Nov 2010, 13:21

Nobody?
Eclipse Helios.
JSF-2.0 (Mojarra 2.1.0-b11).
GlassFish 3.1.
PrimeFaces 2.2.1
EclipseLink 2.1.x - EclipseLink 2.1.x.
PostgreSQL 9.0

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

29 Nov 2010, 17:46

Make sure you are really using the latest version of PrimeFaces and that you do not have more than one PrimeFaces jar in your classpath (check application server extensions and web application archives).

Make sure you can run the showcase in your local environment.

jlferreira
Posts: 43
Joined: 16 Nov 2010, 17:52

29 Nov 2010, 18:42

Nope...
I removed all the primefaces's jars from my computer.
There are only one primeface library in my computer, at project/WebContent/WEB-INF/lib/primefaces-2.2.RC2.jar.

The only thing that I did was rename the file downloaded from primefaces.org from .zip to .jar.

Any other Idea?

Thanks for reponse.
Eclipse Helios.
JSF-2.0 (Mojarra 2.1.0-b11).
GlassFish 3.1.
PrimeFaces 2.2.1
EclipseLink 2.1.x - EclipseLink 2.1.x.
PostgreSQL 9.0

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

29 Nov 2010, 18:50

It doesn't sound like you are having the same problem as I had because the problem I encountered was a bug that was fixed:

http://code.google.com/p/primefaces/sou ... ail?r=3507

My recommendation for you is to get the showcase working locally and then use it as a base to make your changes and see which changes you make cause the problems.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 71 guests