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

import java.math.BigDecimal;
import org.zkoss.util.resource.Labels;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Constraint;

/**
 *
 * @author Administrador
 */
public class ConstraintPorcentagem implements Constraint {

    public void validate(Component comp, Object value) throws WrongValueException {
        if (value == null) {
            throw new WrongValueException(comp,
                    Labels.getLabel("MSG.CONSTRAINT.PORCENTAGEM"));
        } else if (((BigDecimal) value).doubleValue() > 100) {
            throw new WrongValueException(comp,
                    Labels.getLabel("MSG.CONSTRAINT.PORCENTAGEM"));
        } else if (((BigDecimal) value).doubleValue() < 0) {
            throw new WrongValueException(comp,
                    Labels.getLabel("MSG.CONSTRAINT.PORCENTAGEM"));
        }
    }
}
