c12
c12

Reputation: 9827

JSF immediate=true to Skip Validation

Shouldn't the immediate="true" of the commandLink skip validation? I'm still getting the "password is Required" message when I click that link, any ideas?

<h:inputSecret id="j_password" autocomplete="off" value="#{authenticationBean.password}" required="true" requiredMessage="Password is Required" />

<p:commandLink action="#{authentication.forgotPassword}" ajax="false">
    <h:outputText value="#{bundle['login.forgotpassword.TEXT']}" immediate="true"/>
</p:commandLink>

Upvotes: 0

Views: 2860

Answers (3)

Ilya Budu
Ilya Budu

Reputation: 119

The <o:validateBean> allows the developer to control bean validation on a per-UICommand or UIInput component basis, as well as validating a given bean at the class level.

The standard only allows validation control on a per-form or a per-request basis (by using multiple tags and conditional EL expressions in its attributes) which may end up in boilerplate code. The standard also, despite its name, does not actually have any facilities to validate a bean at all.

<o:validateBean disabled="true"/> that command will skip Validations

<p:commandButton 
            id="refresh"
            icon="fa fa-refresh"
            styleClass="refresh-button btn-blue"
            process="@form"
            update="phone_1 @form:htmlView">
   <o:validateBean disabled="true"/>
</p:commandButton>

OR

The <o:skipValidators> taghandler allows the developer to entirely skip validation when executing an UICommand or ClientBehaviorHolder action. This taghandler must be placed inside an UICommand or ClientBehaviorHolder component (client behavior holder components are those components supporting <f:ajax>).

<p:commandButton 
      id="refresh"
      icon="fa fa-refresh"
      styleClass="refresh-button btn-blue"
      process="@form"
      update="phone_1 @form:htmlView">
   <o:skipValidators/>
</p:commandButton>

If you want to know more just look here :

http://showcase.omnifaces.org/validators/validateBean http://showcase.omnifaces.org/taghandlers/skipValidators

Upvotes: 0

moxprox
moxprox

Reputation: 141

The immediate attribute does not skip any validation. It moves the component and all its events, validators etc to the APPLY_REQUEST Phase. So that you have an opportunity to process inputs and commands before all other non-immediate inputs and commands.

http://www.javacodegeeks.com/2012/01/jsf-and-immediate-attribute-command.html

If you want to skip validation with immediate, you will have to take an appropriate action in the event of the immediate action to avoid further processing of inputs and theirs events, like a FacesContext Redirect.

Upvotes: 1

BalusC
BalusC

Reputation: 1108612

You've put it on the <h:outputText> instead of the <p:commandLink>. The immediate attribute has no effect on UIOutput components (and would yield a XML validation error on some environments as well), it has effect on UIInput and UICommand components only. Move the attribute to the <p:commandLink> component.

Upvotes: 1

Related Questions