JIRA中输入验证时,将验证错误“InvalidInputException”写到对应字段顶部,而不是页面顶部。
Posted on 2013-03-27 17:46 Bruce Zhang 阅读(456) 评论(0) 编辑 收藏 举报JIRA now interrogates the InvalidInputException and puts field specific error messages onto the screen.
NOTE : Its up to the validator to ensure it gets the field names right for the current screen scheme.
For example here is example of a Validator that can put specific errors onto specific fields on the default screen.
public class EvilValidator implements Validator { public void validate(Map transientVars, Map args, PropertySet ps) throws InvalidInputException { Issue issue = (Issue) transientVars.get("issue"); Map errorMap = new HashMap(); checkForEvil(issue, errorMap); if (errorMap.size() > 0) { InvalidInputException inputException = new InvalidInputException("Evil has been detected"); for (Iterator iterator = errorMap.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); inputException.addError((String) entry.getKey(), (String) entry.getValue()); } throw inputException; } } private void checkForEvil(Issue issue, Map errorMap) { String desc = issue.getDescription(); if (isEvil(desc)) { errorMap.put(IssueFieldConstants.DESCRIPTION, "Evil is incarnate in the description"); } String env = issue.getEnvironment(); if (isEvil(env)) { errorMap.put(IssueFieldConstants.ENVIRONMENT, "Evil is incarnate in the environment"); } String summary = issue.getSummary(); if (isEvil(summary)) { errorMap.put(IssueFieldConstants.SUMMARY, "Evil is incarnate in the summary"); } } private boolean isEvil(final String input) { return input != null && input.indexOf("evil") != -1; } }