您的位置:首页 > 其它

JIRA中输入验证时,将验证错误“InvalidInputException”写到对应字段顶部,而不是页面顶部。

2013-03-27 17:46 507 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐