Skip to content

Instantly share code, notes, and snippets.

@MoriTanosuke
Created September 26, 2012 09:39
Show Gist options
  • Select an option

  • Save MoriTanosuke/3787046 to your computer and use it in GitHub Desktop.

Select an option

Save MoriTanosuke/3787046 to your computer and use it in GitHub Desktop.
@SuppressWarnings("unchecked")
protected void addError(String key, ActionErrors actionErrors, ActionError errorToAdd){
if(StringUtils.isNotBlank(key) && actionErrors != null && errorToAdd != null){
Iterator<ActionError> it = actionErrors.get(key);
boolean okToAdd = true;
//empty iterator returned where key not in action errors so no need for null check
while(it.hasNext()){
ActionError error = it.next();
if(StringUtils.equals(error.getKey(), errorToAdd.getKey())){
okToAdd = false;
}
}
if(okToAdd){
actionErrors.add(key, errorToAdd);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment