Package org.xulfaces.tag

Source Code of org.xulfaces.tag.ModelTag

/*
*   xulfaces : bring XUL power to Java
*  
*  Copyright (C) 2005  Olivier SCHMITT
*  This library 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 library 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 library; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

package org.xulfaces.tag;

import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;

import org.xulfaces.annotation.taglib.ATTRIBUTE;
import org.xulfaces.annotation.taglib.TAG;

/**
*
* @author kito31
* @version $Id: ModelTag.java,v 1.6 2006/01/10 22:59:13 kito31 Exp $
*/
@TAG(name = "model", process = false)
public class ModelTag extends XULComponentTag {

  private static final Class[] VALIDATOR_ARGS = {FacesContext.class,
        UIComponent.class,
        Object.class};
 
  @ATTRIBUTE(rtexprvalue = true, description = "Value.")
  private String value;

  @ATTRIBUTE(rtexprvalue = true, description = "Validator.")
  private String validator;

  public String getValue() {
    return value;
  }

  public void setValue(String value) {
    this.value = value;
  }

  public String getValidator() {
    return validator;
  }

  public void setValidator(String validator) {
    this.validator = validator;
  }

  protected void setProperties(UIComponent component) {
    super.setProperties(component);
    setProperty(getFacesContext(), component, "value", getValue());
    setValidatorProperty(getFacesContext(),component,getValidator());
  }

  public static void setValidatorProperty(FacesContext context, UIComponent component, String validator) {
    if (validator != null) {
      if (!(component instanceof EditableValueHolder)) {
        throw new IllegalArgumentException("Component " + component.getClientId(context)
            + " is no EditableValueHolder");
      }
      if (isValueReference(validator)) {
        MethodBinding mb = context.getApplication().createMethodBinding(validator, VALIDATOR_ARGS);
        ((EditableValueHolder) component).setValidator(mb);
      }
    }
  }

}
TOP

Related Classes of org.xulfaces.tag.ModelTag

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.