Check for validation errors in part of a form in JSF

霸气de小男生 提交于 2019-12-11 04:12:16

问题


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.

Something like:

<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>

I figured I had two options:

  • Using some sort of view-logic (like #{invalid} for a single field)
  • Using a method in the bean, where I get all components for the module programmatically, and check them for validation errors.

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

We're using JSF 1.2 with Seam.

Thanks.


回答1:


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>


来源:https://stackoverflow.com/questions/6775887/check-for-validation-errors-in-part-of-a-form-in-jsf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!