在具有“for”标记的合成组件中使用Omnifaces Validator

时间:2013-01-28 12:25:15

标签: jsf validation composite-component omnifaces

我想使用omnifaces库中的o:validator标签作为合成组件:

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<cc:interface>
    <cc:attribute name="disabled" />
    <cc:attribute name="label" />
    <cc:attribute name="validatorMessage" />
    <cc:attribute name="required" />
    <cc:attribute name="value" required="true" />
    <cc:editableValueHolder name="date" targets="textfield"/>
</cc:interface>
<cc:implementation>
    <p:outputLabel id="label" for="textfield" value="#{cc.attrs.label}" rendered="#{cc.attrs.label!=null}" />
    <p:inputText id="textfield" value="#{cc.attrs.value}" styleClass="dateInputField" required="#{cc.attrs.required}" disabled="#{cc.attrs.disabled}">      
        <f:convertDateTime locale="de_DE" type="date" />
        <!-- some other stuff... -->
    </p:inputText>
    <p:watermark for="textfield" value="TT.MM.JJJJ" />  
    <cc:insertChildren/>
</cc:implementation>

验证器被调用如下:

<o:validator validatorId="customGreaterThanValidator" compareTo="#{bean.date}" validatorMessage="given date must be later than #{bean.date}" for="date"/>

但不幸的是,似乎来自omnifaces的验证器标签忽略了&#34; for&#34;属性。使用来自JSF的原始验证器标签&#34; for&#34;标签有效,但如果&#34; compareTo&#34; tag是一个ValueExpression。

我尝试实现自定义标记处理程序,但这也不起作用。

1 个答案:

答案 0 :(得分:0)

当前的1.3 <o:validator>(也不是<o:converter>)确实不支持此功能。根据{{​​3}}(您可以下载快照),它将在未来1.4中出现。

关键是分别将TagHandler更改为issue 126ValidatorHandler,以便ConverterHandler可以为复合材料完成工作。