跳过所需的验证并调用应用程序 [英] Skip required validation and invoke the application

查看:102
本文介绍了跳过所需的验证并调用应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此处问了我的问题,但我认为它缺少一些明显的信息.因此,我再次发布我的问题.

I asked my question here but I think it lacks some obvious information. Hence I'm posting my question again.

我有一个JSF表单,该表单对h:inputText字段具有一些必需的验证.提交表单时,我想跳过(或忽略)所需的验证检查并仍然调用应用程序.我确实想进行表单数据验证,并根据某些情况显示错误.

I have a JSF form which has some required validation on h:inputText fields. When submitting the form I want to skip(or ignore) the required validation check and still invoke the application. I do want to do the form data validation and show the errors based on some condition.

基本上,我想跳过验证并在使用ajax调用提交表单时调用应用程序,而在单击提交按钮提交表单时进行验证.

Basically I want to skip the validations and invoke the application when the form is submitted using an ajax call and do the validation when the form is submitted via clicking a submit button.

推荐答案

只需将那个条件直接放在required属性中即可.

Just put that condition straight in the required attribute.

<h:inputText ... required="#{someCondition}" />

它就像其他许多属性一样,只接受任何EL表达式.许多入门者认为,您只能在其中硬编码"true""false"字符串.这是不正确的.

It namely just accepts any EL expression like as many other attributes. Many starters think that you can only hardcode a "true" or "false" string in it. This is untrue.

例如,当您要让它仅在实际按下保存按钮时才对true求值:

For example, when you want to let it evaluate true only when the save button is actually pressed:

<h:inputText ... required="#{not empty param[save.clientId]}" />
...
<h:commandButton value="Cancel" ... />
<h:commandButton binding="#{save}" value="Save" ... />

(注意:代码按原样完整,您不需要将其绑定到bean属性)

(note: code is complete as-is, you do not need to bind it to a bean property)

通过这种方式,required属性仅在按下保存按钮时才评估true,并且对于其他任何按钮或ajax事件侦听器均评估false.

This way the required attribute only evaluates true when the save button is pressed and it evaluates false for any other button or ajax event listener.

这篇关于跳过所需的验证并调用应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆