zoukankan      html  css  js  c++  java
  • JIRA中输入验证时,将验证错误“InvalidInputException”写到对应字段顶部,而不是页面顶部。

    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;
        }
    }

     参照:https://jira.atlassian.com/browse/JRA-12886

  • 相关阅读:
    未格式化的输入/输出操作
    格式化输入与输出
    随机数
    正则表达式
    bitset
    tuple
    servlet笔记
    springside
    maven
    Lua简易入门教程
  • 原文地址:https://www.cnblogs.com/zhangqingsh/p/2985100.html
Copyright © 2011-2022 走看看