All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.seam.faces.validation.InputField Maven / Gradle / Ivy

The newest version!
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.seam.faces.validation;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.enterprise.util.Nonbinding;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.inject.Qualifier;

/**
 * To be used in conjunction with <s:validateForm /> in
 * Validators that should have their values fetched from a JSF form field.
 * 

* Example: *

* * * public @{@link FacesValidator}("locationValidator") class * LocationValidator implements {@link Validator} {

* *     public @Field String city;
    * public @Field String state;
    public * * @Field("zip") String zipcode;

    public void * validate(FacesContext context, UIComponent comp, Object * componentMap
    {
*        * //validate like usual.
    }

} *

* Note: The annotation value @Field("id") Specifies the * default clientId alias for which values will be bound to the * field annotated by this annotation. * * <h:form id="form">
*     <h:inputText id="cityId" * value="#{bean.city}" />
*     <h:inputText id="state" * value="#{bean.state}" />
*     <h:inputText id="zip" * value="#{bean.zip}" />
*     <h:commandButton id="submit" * value="Submit" action="#{bean.submit}" * /> *

*     <s:validateForm * fields="city=cityId" * validatorId="locationValidator" />
* </h:form>
*

* Notice in the above example, that not all fields must be * specified in the validator tag. If the Facelet field IDs match * the validator fields, the values will automatically be mapped * to the validator. *

* Fields can also be mapped to the validator through a simple * alias: "validatorFieldId=componentClientId", where * validatorFieldId is the name of the annotated @Field in the * Validator, and componentClientId is the ID of the input * component relative to the form in which it resides. *

* When writing your public void validate(FacesContext context, * UIComponent comp, Object componentMap) method, keep in mind * the following differences from a normal validator: *

    *
  • "comp" is the parent UIForm that contains this * <s:validateForm /> tag.
  • *
  • "componentMap" is a map of the requested input field names, * and their corresponding UIInput component objects. This allows * programmatic access to each of the components being validated.
  • *
* * @author




© 2015 - 2024 Weber Informatics LLC | Privacy Policy