点击一个特定的按钮时如何跳过验证? [英] How to skip validation when a specific button is clicked?

查看:206
本文介绍了点击一个特定的按钮时如何跳过验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在一个字段校验器的形式。我有两个 H:的commandButton 取值:确定和取消。当我开关输入错误的数据,然后单击取消,我得到一个验证消息。我必须这样做验证,当我点击取消不跑?

I have a form with a validator on one field. I have two h:commandButtons: Ok and Cancel. When I imput wrong data and click Cancel I get a validation message. What must I do that validator don't run when I click cancel?

推荐答案

如果你不使用AJAX,或仍对JSF 1.x中,并且你确实需要在取消()方法(即只重新加载页面不足),那么最好的办法是添加立即=真正的的按钮。这样,所有输入字段不具有立即=真正的将在处理被跳过。

In case you aren't using ajax, or are still on JSF 1.x, and you really need to invoke a business action in cancel() method (i.e. just reloading the page is insufficient), then your best bet is to add immediate="true" to the button. This way all input fields which don't have immediate="true" will be skipped in processing.

<h:commandButton value="Cancel" action="#{bean.cancel}" immediate="true" />

在JSF 2.x中,更好的是&LT提交表单; F:AJAX&GT; ,它在默认情况下只流程 @this 而不是 @form

On JSF 2.x, much better is to submit the form by <f:ajax>, which by default only processes @this instead of @form.

<h:commandButton value="Cancel" action="#{bean.cancel}">
    <f:ajax />
</h:commandButton>

如果你想在这里导航到另一个页面,添加?面临重定向=真正来的成果取消()方法。

If you want to navigate to another page here, add ?faces-redirect=true to the outcome in the cancel() method.

或者,如果你其实并不需要在所有调用任何商业行为,那么就使用&LT; H:按钮&GT; ,其中你直接指定(隐含的)导航的情况下的结果。

Or, if you actually don't need to invoke any business action at all, then just use <h:button> wherein you directly specify the (implicit) navigation case outcome.

<h:button value="Cancel" outcome="previouspage" />

这将基本上是由一个GET请求重新加载页面。在&LT; H:按钮&GT; 不JSF 1.x中存在的,但你也可以只使用纯HTML + JS为

This will basically reload the page by a GET request. The <h:button> doesn't exist in JSF 1.x, but you can also just use plain HTML+JS for that.

  • Why was "immediate" property added to the EditableValueHolders?
  • How to navigate in JSF? How to make URL reflect current page (and not previous one)
  • How to let validation depend on the pressed button?

这篇关于点击一个特定的按钮时如何跳过验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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