OmniFaces 2.3 comes with a new tag handler named SkipValidators.
As its name suggest, this tag handler allows us to entirely skip validation
when executing an UICommand
or ClientBehaviorHolder
action. Simply place the
<o:skipValidators/> tag inside a UICommand or ClientBehaviorHolder component. For example,
in the below code, the button labeled Hard Submit will take validation into account, while the
button labeled Soft
Submit will entirely skip validation and the submitted data end up in the data model:
<h:form>
<h:messages/>
<h:panelGrid columns="2">
<h:outputLabel for="nameId"
value="Name:"/>
<h:inputText id="nameId"
value="#{dataBean.name}" required="true"/>
<h:outputLabel for="emailId"
value="E-mail:"/>
<h:inputText id="emailId"
value="#{dataBean.email}" required="true"
validator="emailValidator"/>
<h:commandButton value="Hard
Submit"/>
<h:commandButton value="Soft
Submit">
<o:skipValidators />
</h:commandButton>
</h:panelGrid>
Name: #{dataBean.name} | E-mail:
#{dataBean.email}
</h:form>
Note Even if the validation
is disabled conversion errors could still occur.
This can be useful in different scenarios including debugging, testing, dynamically adding/removing items from a form, etc. You can temporary disable the validation for large forms and perform different checks with respect to data model. Instead of removing validators one by one, you simply add this tag handler. The complete application is available here.
Niciun comentariu :
Trimiteți un comentariu