本文整理汇总了Java中net.sourceforge.stripes.validation.ValidationError.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java ValidationError.getMessage方法的具体用法?Java ValidationError.getMessage怎么用?Java ValidationError.getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sourceforge.stripes.validation.ValidationError
的用法示例。
在下文中一共展示了ValidationError.getMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logValidationErrors
import net.sourceforge.stripes.validation.ValidationError; //导入方法依赖的package包/类
/** Log validation errors at DEBUG to help during development. */
public static final void logValidationErrors(ActionBeanContext context) {
StringBuilder buf = new StringBuilder("The following validation errors need to be fixed:");
for (List<ValidationError> list : context.getValidationErrors().values()) {
for (ValidationError error : list) {
String fieldName = error.getFieldName();
if (ValidationErrors.GLOBAL_ERROR.equals(fieldName))
fieldName = "GLOBAL";
String message;
try {
message = error.getMessage(Locale.getDefault());
}
catch (MissingResourceException e) {
message = "(missing resource)";
}
buf.append("\n -> [").append(fieldName).append("] ").append(message);
}
}
log.debug(buf);
}
示例2: doEndTag
import net.sourceforge.stripes.validation.ValidationError; //导入方法依赖的package包/类
/**
* Output the error list if this was an empty body tag and we're fully controlling output*
*
* @return EVAL_PAGE always
* @throws JspException
*/
@Override
public int doEndTag() throws JspException {
try {
JspWriter writer = getPageContext().getOut();
if (this.display && !this.nestedErrorTagPresent) {
// Output all errors in a standard format
Locale locale = getPageContext().getRequest().getLocale();
ResourceBundle bundle = null;
try {
bundle = StripesFilter.getConfiguration()
.getLocalizationBundleFactory().getErrorMessageBundle(locale);
}
catch (MissingResourceException mre) {
log.warn("The errors tag could not find the error messages resource bundle. ",
"As a result default headers/footers etc. will be used. Check that ",
"you have a StripesResources.properties in your classpath (unless ",
"of course you have configured a different bundle).");
}
// Fetch the header and footer
String header = getResource(bundle, "header", DEFAULT_HEADER);
String footer = getResource(bundle, "footer", DEFAULT_FOOTER);
String openElement = getResource(bundle, "beforeError", "<li>");
String closeElement = getResource(bundle, "afterError", "</li>");
// Write out the error messages
writer.write(header);
for (ValidationError fieldError : this.allErrors) {
String message = fieldError.getMessage(locale);
if (message != null && message.length() > 0) {
writer.write(openElement);
writer.write(message);
writer.write(closeElement);
}
}
writer.write(footer);
}
else if (this.display && this.nestedErrorTagPresent) {
// Output the collective body content
getBodyContent().writeOut(writer);
}
// Reset the instance state in case the container decides to pool the tag
this.display = false;
this.nestedErrorTagPresent = false;
this.allErrors = null;
this.errorIterator = null;
this.currentError = null;
this.index = 0;
return EVAL_PAGE;
}
catch (IOException e) {
JspException jspe = new JspException("IOException encountered while writing errors " +
"tag to the JspWriter.", e);
log.warn(jspe);
throw jspe;
}
}
示例3: removeDuplicates
import net.sourceforge.stripes.validation.ValidationError; //导入方法依赖的package包/类
/**
* Sometimes error messages can be the same even although different fields
* are involved. Also, if 2 different types of validations occur on one
* field, then stripes will display them both. We want neither, so here we
* attempts to remove any duplicates.
*
* @param validationErrors
*/
protected void removeDuplicates(ValidationErrors validationErrors) {
List<String> allErrorMessages = new ArrayList<String>();
if (validationErrors.size() > 0) {
Set<String> keys = validationErrors.keySet();
for (String field : keys) {
List<ValidationError> errors = validationErrors.get(field);
// Remember errors we want to remove.
List<ValidationError> errorsToRemove = new ArrayList<>();
// Remember errors that we want to add in place of the removed
// ones.
Set<ValidationError> errorsToAdd = new HashSet<>();
int count = 0;
for (ValidationError error : errors) {
// If a field has more than one error, we remove all of the
// rest. We only want to show one error at
// a time per field.
if (errors.size() > 0 && count > 0) {
errorsToRemove.add(error);
continue;
}
// Set the bean class or strips end up with a NullPointer.
// error.setBeanclass(app.getActionBean().getClass()); //
// Not needed in Geemvc.
String message = error.getMessage(app.getCurrentLocale());
// If this message already exists, we remove it from the
// list of errors.
if (allErrorMessages.contains(message)) {
errorsToRemove.add(error);
// Errors that we remove need to be replaced with some
// empty error or stripes will not
// re-populate the input-field.
errorsToAdd.add(new SimpleError("", null, error.getFieldValue()));
} else {
// Remember the error message in the global list so that
// we can check for duplicates in other
// fields.
allErrorMessages.add(message);
}
count++;
}
if (errorsToRemove.size() > 0) {
errors.removeAll(errorsToRemove);
errors.addAll(errorsToAdd);
}
}
}
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:64,代码来源:ActionBeanPropertyBinder.java