com.webbfontaine.valuewebb.model.validators.TemplateValidator.java Source code

Java tutorial

Introduction

Here is the source code for com.webbfontaine.valuewebb.model.validators.TemplateValidator.java

Source

package com.webbfontaine.valuewebb.model.validators;

import com.webbfontaine.valuewebb.model.Pd;
import com.webbfontaine.valuewebb.model.constants.Messages;
import com.webbfontaine.valuewebb.model.template.TemplateSpec;
import com.webbfontaine.valuewebb.validation.ErrorHandling;
import org.apache.commons.lang3.StringUtils;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 * Copyrights 2002-2013 Webb Fontaine
 * This software is the proprietary information of Webb Fontaine.
 * Its use is subject to License terms.
 * Developer: nigiyan
 * Date: 10/06/2013
 */

public class TemplateValidator implements Validator/*, ValueChangeListener*/ {

    private static final Log LOGGER = Logging.getLog(TemplateValidator.class);

    @Override
    public void validate(FacesContext facesContext, UIComponent uiComponent, Object value)
            throws ValidatorException {
        LOGGER.debug("Starting to execute validator");

        CharSequence enteredValue = (CharSequence) value;
        Pd pd = (Pd) Component.getInstance("pdInstance", ScopeType.EVENT, true);

        if (!StringUtils.isEmpty(pd.getHsCodeF()) && StringUtils.isEmpty(enteredValue)) {
            TemplateSpec templateSpec = pd.getFtemplate().getSpec();
            String id = uiComponent.getId();
            if (TemplateSpec.checkRequired(templateSpec.getField(id), pd.getHsCodeF())) {
                ErrorHandling.addFacesMessageError(uiComponent.getClientId(facesContext),
                        Messages.VALUE_IS_REQUIRED);
            }
        }
    }

    /*    @Override
        public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
    validate(FacesContext.getCurrentInstance(), event.getComponent(), event.getNewValue());
        }*/
}