OmniFaces禁用o:验证器

时间:2015-02-19 17:17:54

标签: jsf omnifaces

根据这个Disable validator via ajax,我认为我可以这样做:

<p:inputText 
<o:validator validatorId="javax.faces.DoubleRange" disabled="controller.item.type != 'M'" minimum='0.75' maximum='0.99' for="factor"/>
<o:validator validatorId="javax.faces.DoubleRange" disabled="controller.item.type != 'U'" minimum="0.5" maximum="0.74" for="factor"/>
<o:validator validatorId="javax.faces.DoubleRange" disabled="controller.item.type != 'N'" minimum="0.0" maximum="0.49" for="factor"/>
</p:inputText>

但验证者消息不能反映正确的验证。最后,我只是想根据用户在oneSelectMenu中选择的内容来引导用户输入输入范围。

完整代码位于

之下
<h:outputLabel for="type" value="Probability" />
<p:selectOneMenu id="type" value="#{controller.item.type}">
    <f:selectItem itemValue="A" itemLabel="Absolutely" />
    <f:selectItem itemValue="M" itemLabel="Maybe" />
    <f:selectItem itemValue="U" itemLabel="Unsure" />
    <f:selectItem itemValue="N" itemLabel="Not Likely" />
    <f:ajax render="@form" />                           
</p:selectOneMenu>
<p:message for="type" />


<h:outputLabel for="factor" value="Factor" />

<h:panelGroup>
<p:inputText id="factor" value="#{controller.item.factor}" size="4" rendered="#{controller.item.type == 'M' || controller.item.type == 'U' || controller.item.type == 'N' }"
required="#{controller.item.type == 'M' || controller.item.type == 'U' || controller.item.type == 'N' }" requiredMessage="Factor is required">
<o:validator validatorId="javax.faces.DoubleRange" disabled="controller.item.type != 'M'" minimum='0.75' maximum='0.99' for="factor"/>
<o:validator validatorId="javax.faces.DoubleRange" disabled="controller.item.type != 'U'" minimum="0.5" maximum="0.74" for="factor"/>
<o:validator validatorId="javax.faces.DoubleRange" disabled="controller.item.type != 'N'" minimum="0.0" maximum="0.49" for="factor"/>

</p:inputText>

<h:outputLabel id="absolutelyFactor" value="Absolutely (1.00)"
rendered="#{controller.item.type == 'A' || empty controller.item.type}" />

<h:outputLabel id="maybeFactor" value="Maybe (0.75-0.99)"
rendered="#{controller.item.type == 'M'}" />

<h:outputLabel id="UnsureFactor" value="Unsure (0.50-0.74)"
rendered="#{controller.item.type == 'U'}" />

<h:outputLabel id="NLFactor" value="Not Likely (0.00-0.49)"
rendered="#{controller.item.type == 'N'}" />
</h:panelGroup>

<p:message for="factor" />

修改 根据BalusC的敏锐眼光,我在残疾人中没有真正的EL表达。这很有效。

<o:validator validatorId="javax.faces.DoubleRange" disabled="#{controller.item.type != 'M'}" minimum='0.75' maximum='0.99' message="Factor is not in range 0.75-0.99"/>

0 个答案:

没有答案