/*
 * Copyright (c) 2007 NTT DATA Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jp.terasoluna.rich.functionsample.inputcheck.validator;

import org.springframework.validation.Errors;
import jp.terasoluna.fw.validation.springmodules.BaseMultiFieldValidator;
import jp.terasoluna.rich.functionsample.inputcheck.bean.CodingData;

/**
 * コーディングによる入力チェックするクラス
 *
 */
public class CodingMultiFieldsValidator extends BaseMultiFieldValidator {

    /**
     * 相関チェックを行なう。
     *
     * @param obj 入力クラス
     * @param errors エラークラス
     */
    @Override
    protected void validateMultiField(Object obj, Errors errors) {
        
        CodingData bean = (CodingData) obj;
        
        // JavaBeanから値を取り出す
        int field1 = Integer.parseInt(bean.getField1());
        int field2 = Integer.parseInt(bean.getField2());
        
        // feild2はfeild1より大きい数字になることは禁止される。
        if (field1 < field2) {
            errors.rejectValue("field1", "errors.UC109.00001",
                    new String[]{"field1", "field2"}, "");
        }
    }
}
