【问题标题】:Problems when using validator inside a p:dataTable在 p:dataTable 中使用验证器时出现问题
【发布时间】:2012-04-24 15:54:21
【问题描述】:

当我在 dataTable 的字段中使用 f:validator 时,它不起作用,如果我在我的验证器类中插入断点,它永远不会执行。

我的数据表:

<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>

我的班级: 包 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"));
    }
}

【问题讨论】:

  • 您在给定代码中不使用f:validator,而是使用validator 属性(通常应该相同)。但是你有没有尝试过f:validator
  • 是的,首先,我使用了 f:validator 标签。

标签: jsf primefaces datatable validation


【解决方案1】:

确保#{contrato} bean 至少为@ViewScoped。确保您没有在其 getter 方法中准备 plantillaPrograma,而是在 bean 的(后)构造函数中准备。确保dateConverter 没有抛出ConverterException,您应该通过&lt;h:message(s)&gt; 或服务器日志中的面孔消息注意到这一点。

顺便问一下,你为什么不直接使用内置的&lt;f:convertDateTime&gt; 来表示日期?

【讨论】:

  • 你好,bean是viewScoped,在fileUpload方法中生成plantillaPrograma(上传一个excel文件我生成表),dateConverter没有抛出任何异常,我检查了服务器日志,有没有错。我正在使用 sutom 转换器,因为当我开始制作应用程序的架构时,我定义了一些转换器,可能忽略了已经实现的转换器,但转换器工作正常,问题出在验证器上。我不知道为什么,但这只发生在我在数据表中使用时,在其他视图中,工作正常。感谢您的回答
【解决方案2】:

解决了。

我的问题出在命令按钮上,我有属性 process="@this",删除后,验证工作正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    相关资源
    最近更新 更多