在JSF中检查表单中的一部分验证错误 [英] Check for validation errors in part of a form in JSF

查看:86
本文介绍了在JSF中检查表单中的一部分验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Seam应用程序,它基本上是一个巨大的表格,分为不同的部分或模块.我需要一种方法来弄清楚模块何时完成",这意味着该模块中所有字段的所有验证都将通过.然后,我需要在视图中做一些事情,设置css类或其他内容.

I'm building a Seam application, which is basically a huge form divided into different parts, or modules. I need a way to figure out when a module is "complete", meaning all validation for the fields in that module passes. I then need to do something in the view, setting a css-class or whatever.

类似的东西:

<a:region id="region1">
    <s:div styleClass="#{invalid ? 'errors' : ''}">
       <h:inputText required="true" id="input1" />
       <h:inputText required="true" id="input2" />
       <h:commandButton value="Save this section" reRender="region1" />
    </s:div>
</a:region>

我认为我有两个选择:

  • 使用某种视图逻辑(例如对单个字段使用#{invalid})
  • 使用Bean中的方法,在该方法中以编程方式获取模块的所有组件,并检查它们是否存在验证错误.

但是,我找不到任何方法来做其中的任何一个.有什么可能的想法吗?

However, I can't find any way to do any of them. Any ideas if this is even possible?

我们在Seam中使用了JSF 1.2.

We're using JSF 1.2 with Seam.

谢谢.

推荐答案

您可以使用

You can use UIInput#isValid() to check if a validation error has occurred on the particular input component.

<s:div styleClass="#{!input1.valid or !input2.valid ? 'errors' : ''}">
   <h:inputText binding="#{input1}" required="true" id="input1" />
   <h:inputText binding="#{input2}" required="true" id="input2" />
   <h:commandButton value="Save this section" reRender="region1" />
</s:div>

这篇关于在JSF中检查表单中的一部分验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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