enterhoursvalidator.java

来自「Java 敏捷开发--使用Spring Hibernate 和 Eclipse源」· Java 代码 · 共 34 行

JAVA
34
字号
package com.visualpatterns.timex.controller;

import org.springframework.validation.Errors;
import com.visualpatterns.timex.model.Timesheet;

/**
 * Validator for EnterHoursController
 * @author anil
 * @see com.visualpatterns.timex.controller.EnterHoursController
 */
public class EnterHoursValidator implements
        org.springframework.validation.Validator
{
    public boolean supports(Class clazz)
    {
        return clazz.equals(Timesheet.class);
    }

    /**
     * Validates the Timesheet command object.  Ensures that the
     * departmentCode is specified.
     * @see Timesheet 
     */
    public void validate(Object command, Errors errors)
    {
        Timesheet timesheet = (Timesheet) command;
        if (timesheet == null) return;

        if (timesheet.getDepartmentCode() == null
                || timesheet.getDepartmentCode().trim().length() < 1)
            errors.reject("error.enterhours.missingdepartment");
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?