/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.corejsf;

import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.event.MethodExpressionValueChangeListener;
import javax.faces.webapp.UIComponentELTag;

/**
 *
 * @author CNOC
 */
public class SpinnerTag extends UIComponentELTag {

    public String getComponentType() {
        return "spinner";
    }

    public String getRendererType() {
        return null;
    }
    private ValueExpression minimum;
    private ValueExpression maximum;
    private ValueExpression size;
    private ValueExpression value;
    private ValueExpression readonly;
    private ValueExpression step;
    private MethodExpression valueChangeListener = null;

    public void setMinimum(ValueExpression minimum) {
        this.minimum = minimum;
    }

    public void setMaximum(ValueExpression maximum) {
        this.maximum = maximum;
    }

    public void setSize(ValueExpression size) {
        this.size = size;
    }

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

    public void setReadonly(ValueExpression readonly) {
        this.readonly = readonly;
    }

    public void setStep(ValueExpression step) {
        this.step = step;
    }

    public void setProperties(UIComponent component) {

        super.setProperties(component);
        component.setValueExpression("size", size);
        component.setValueExpression("minimum", minimum);
        component.setValueExpression("maximum", maximum);
        component.setValueExpression("value", value);
        component.setValueExpression("readonly", readonly);
        component.setValueExpression("step", step);
        if (valueChangeListener != null) {
            ((EditableValueHolder) component).addValueChangeListener(new MethodExpressionValueChangeListener(valueChangeListener));
        }
    }

    public void release() {
// always call the superclass method
        super.release();
        minimum = null;
        maximum = null;
        size = null;
        value = null;
    }

    public MethodExpression getValueChangeListener() {
        return valueChangeListener;
    }

    public void setValueChangeListener(MethodExpression valueChangeListener) {
        this.valueChangeListener = valueChangeListener;
    }
}
