Problems when using validator inside dataTable

UI Components for JSF
Post Reply
Didvae
Posts: 3
Joined: 25 Apr 2012, 11:04

25 Apr 2012, 11:10

Hi all,

When I use f:validator inside a field of a dataTable, doesn't work, if I insert a breakpoint in my validator class, it never executes.

My dataTable:

Code: Select all

<p:dataTable value="#{contrato.plantillaPrograma}" var="pl" scrollHeight="300" rendered="#{contrato.abrirPrograma}" autoUpdate="true">
    <p:column headerText="#{txtMsg['crearContrato.fecha']}" style="width:125px"
    sortBy="#{pl.fecha}">
        <h:inputText value="#{pl.fecha}">
            <f:converter converterId="dateConverter" />
        </h:inputText>
    </p:column>
    <p:column headerText="#{txtMsg['crearContrato.programa']}" style="width:125px"
    sortBy="#{pl.programa}">
        <h:inputText value="#{pl.programa}" />
    </p:column>
    <p:column headerText="#{txtMsg['crearContrato.fechaFactura']}" style="width:125px"
    sortBy="#{pl.fechaFactura}">
        <p:inputText value="#{pl.fechaFactura}" validator="sheetEnFirme">
            <f:converter converterId="dateConverter"/>
        </p:inputText>
    </p:column>
</p:dataTable>
My class:

Code: Select all

 package es.axpo.jsf.validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;


@FacesValidator(value="sheetEnFirme")
public class SheetEnFirmeValidator implements Validator{

    public void validate(FacesContext fc, UIComponent comp, Object obj)
            throws ValidatorException {
        throw new ValidatorException(new FacesMessage("Error"));

    }

}
thanks in advance!
Primefaces 3.2,Mojarra 2.1.1,Apache Tomcat 6.0

User avatar
T.dot
Expert Member
Posts: 620
Joined: 01 Feb 2012, 15:39
Location: Vienna/Austria

25 Apr 2012, 11:21

first of all: viewtopic.php?f=3&t=1194

then RTFM: validator - Method Expr: A method binding expression that refers to a method validationg the input
So you can't put a validatorId there. Try <f:validator validatorId="fooBar" /> instead.

Didvae
Posts: 3
Joined: 25 Apr 2012, 11:04

25 Apr 2012, 11:31

Hi T.dot

I already used the f:validator tag, and it's the same.
the bean is viewScoped, and plantillaPrograma is generated in a fileUpload method (Uploading an excel file I generate the table), dateConverter hasn't thrown any exception, I checked server logs, an there is nothing wrong. I'm using sutom converter because when I started making the architecture of the app, I defined some converters, maybe ignoring that there was already implemented, but the converter works fine, the problem is on validator. I don't know why, but this only happens when I use inside a dataTable, in other views, works fine.
Primefaces 3.2,Mojarra 2.1.1,Apache Tomcat 6.0

User avatar
T.dot
Expert Member
Posts: 620
Joined: 01 Feb 2012, 15:39
Location: Vienna/Austria

25 Apr 2012, 12:29

Works in a simple sample. Try to simplify your code to find out where's the difference.

xhtml:

Code: Select all

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<f:view contentType="text/html">
	<h:head>
		<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
	</h:head>

	<h:body styleClass="applicationBody ui-widget">

		<h:form id="form">
			<p:growl autoUpdate="true" />

			<p:dataTable value="#{tableBean2.data}" var="row" rows="5">

				<p:column headerText="header">
					<p:inputText value="#{row.value}">
						<f:validator validatorId="testValidator" />
					</p:inputText>
				</p:column>
			</p:dataTable>

			<p:commandButton action="#{tableBean2.action}" value="submit" />

		</h:form>
	</h:body>
</f:view>
</html>
BackingBean:

Code: Select all

@ManagedBean(name = "tableBean2")
@ViewScoped
public class TableBean2
{
   public static class Dto
   {
      private String value;

      public Dto()
      {

      }

      public Dto( String value )
      {
         this.value = value;
      }

      public String getValue()
      {
         return value;
      }

      public void setValue( String value )
      {
         this.value = value;
      }
   }

   private List<Dto> data;

   public TableBean2()
   {
      data = new ArrayList<Dto>();

      for (int i = 0; i < 5; i++)
      {
         data.add( new Dto( "value " + i ) );
      }
   }

   public List<Dto> getData()
   {
      return data;
   }
   
   public String action() {
      
      FacesContext.getCurrentInstance().addMessage( null, new FacesMessage("action") );
      
      return null;
   }
}

Didvae
Posts: 3
Joined: 25 Apr 2012, 11:04

25 Apr 2012, 13:22

It's solved.

My problem was on the command button, I had property process="@this", when removed, validation works fine

Thanks
Primefaces 3.2,Mojarra 2.1.1,Apache Tomcat 6.0

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

26 Apr 2012, 04:12

Didvae wrote:It's solved.

My problem was on the command button, I had property process="@this", when removed, validation works fine

Thanks
Good find. To this day, i don't have one occurrence of process="..." on any commandButton/Link in my JSF/PrimeFaces web app. I don't see it as necessary at all in my web app.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

User avatar
T.dot
Expert Member
Posts: 620
Joined: 01 Feb 2012, 15:39
Location: Vienna/Austria

27 Apr 2012, 08:52

Good for you. I need it on every complex page.

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

27 Apr 2012, 20:06

T.dot wrote:Good for you. I need it on every complex page.
I may need to review some complex pages and compare to my complex pages. :)
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 27 guests