暂时禁用JSF验证 [英] Temporarily disable JSF validations
问题描述
A具有许多必需的输入和验证.几个命令按钮控制不同的输入.
A has many required inputs and validations. A couple of command buttons control different inputs.
我可以用<f:param>
的值更改所需的着装.例如,当单击一个按钮时,它会设置一个值.无论是否需要输入,此值都会更改.像这样:
I can change required attibrute with the value of <f:param>
. For instance when a button is clicked,it sets a value.This value changes if an input is required or not. Like this:
<p:commandButton>
<f:param name="button1" value="1"></f:param>
</p:commandButton>
<h:inputText required="#{param['button1'] == 1}"></h:inputText>
这实际上有效.但是我还想添加一些限制,例如最大长度.我也想暂时更改此验证.
This actually works.However i also want to add some valitations like max length.I want to temporarily change this validation too.
我试图禁用valitadion,但是我没有用:
I tried to disable valitadion,but i did not work:
<f:validateLength disabled="true" maximum="10"></f:validateLength>
推荐答案
您似乎已经在使用JSF2.x.因此,只需使用<f:ajax execute>
或<p:commandButton process>
来指定按下按钮时将要执行/处理的组件的客户端ID.所有未包含在其中的组件都将被忽略并且不进行转换/验证.
You seem to be using JSF 2.x already. So just use <f:ajax execute>
or <p:commandButton process>
to specify client IDs of components which are to be executed/processed when the button is pressed. All components which are not included in this will just be ignored and not converted/validated.
例如
<h:inputText id="input1" ... required="true" />
<h:inputText id="input2" ... required="true" />
<h:inputText id="input3" ... required="true" />
<h:inputText id="input4" ... required="true" />
<p:commandButton value="Submit inputs 1 and 2" process="input1 input2" ... />
<p:commandButton value="Submit inputs 3 and 4" process="input3 input4" ... />
如果使用<p:commandButton>
,则默认为@form
(即整个当前表格).
In case of <p:commandButton>
it defaults to @form
(i.e. the entire current form).
这篇关于暂时禁用JSF验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!