Mateus Viccari
Mateus Viccari

Reputation: 7699

Programatically set context variable to enable/disable bean validation

In my web.xml, I have this configuration entry:

<context-param>
   <param-name>javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR</param-name>
   <param-value>true</param-value>
</context-param>

However, I don't want it to be always true. I want to set it true or false in my managed bean, depending on the situation. Is that possible?

Upvotes: 1

Views: 850

Answers (1)

BalusC
BalusC

Reputation: 1108632

No, that's the wrong way of solving the concrete problem. For that, the <f:validateBean> tag should actually be used instead.

You can use it on a per-view or per-form basis, most self-documenting would be to just wrap it around the <h:form>. The <h:form> in turn can be just in a template client (and the <f:validateBean> thus in the master template).

<f:validateBean disabled="true">
    <h:form>

    </h:form>
</f:validateBean>

You can even use EL in there.

<f:validateBean disabled="#{settings.beanValidationDisabled}">

Upvotes: 5

Related Questions