You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2005/08/12 19:54:48 UTC

[Myfaces Wiki] Update of "OptionalValidationFramework" by MikeKienenberger

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by MikeKienenberger:
http://wiki.apache.org/myfaces/OptionalValidationFramework

New page:
##language:en
== Optional Validation Framework ==
===== Authors: Mike Kienenberger, Alexander Jesse =====
An optional validation framework is available as module OptionalValidator in cvs for the jsf-comp [http://sourceforge.net/cvs/?group_id=137466 ] project.

This optional validator framework allows you to change the behavior of validators in a form.  JSF allows you limited two-stage control of validation using the immediate attribute.   However, this is only sufficient for trivial use cases.   It does not work well if you have multiple actions requiring multiple validation configurations on the same form.  It also does not provide a warning-only mode where validation errors are reported in a non-fatal manner.

OptionalValidator currently supports three modes: hard (default), soft, and none.

 * "none" means that the validator will not be validated.
 * "soft" means that the validator will be executed, and the FacesMessages generated, but the lifecycle will continue past the processValidations phase.
 * "hard" is the standard JSF behavior, and the validator will perform as normal.

Because the required validation of a component is handled separately from normal validation, you must not use the required attribute.  Instead, there is a RequiredValidator that needs to be used, and a RequiredValidatorChecker component that's added to bottom of your UIForm in order to trigger the RequiredValidators.

The behavior of the optional validators is determined by the setting of the NET_SF_JSFC_OPT_VDTR_MODE request parameter.   Different UICommands can submit different request parameter options.

''Note: it is the responsibility of the end-user developer to know whether any particular component contains valid input for a given action.''

For assistance, send email to mkienenb@gmail.com

=== Example ===
{{{
<html [...] xmlns:jsfcomp="http://sf.net.jsfcomp.validator">
[...]
    <h:form id="form">
        [...]
        <h:inputText value="#{value}">
            <jsfcomp:optionalValidator delegateValidatorId="net.sf.jsfcomp.validator.RequiredValidator"/>
            <jsfcomp:optionalValidator delegateValidatorId="myValidatorId"/>
    	</h:inputText>
        [...]
        <h:commandLink value="Optional action"  action="#{optionalAction}">
            <f:param name="NET_SF_JSFC_OPT_VDTR_MODE" value="none"/>
        </h:commandLink>
        <h:commandLink value="Refresh action"  action="#{refreshAction}">
            <f:param name="NET_SF_JSFC_OPT_VDTR_MODE" value="soft"/>
        </h:commandLink>
        <h:commandLink value="Update action"  action="#{refreshAction}">
            <f:param name="NET_SF_JSFC_OPT_VDTR_MODE" value="hard"/>
        </h:commandLink>
        [...]
        <jsfcomp:requiredValidatorChecker/>
    </h:form>
[...]
</html>
}}} 

=== In progress ===
 * Allow separate mode settings for different groups of validators.
 * Can OptionalValidator mark components as invalid in warning mode?  (Maybe through the RequiredValidatorChecker)