From 60ff93e5ac9d33a5381928cc48feb94f419fe663 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 22 Feb 2010 11:48:08 +0000 Subject: [PATCH] avoid invalid id characters in ErrorsTag as well (SPR-6862) --- .../web/servlet/tags/form/ErrorsTag.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java index 825a2877a9c..ccc1fc160f4 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import javax.servlet.jsp.tagext.BodyTag; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; /** * Form tag for displaying errors for a particular field or object. @@ -100,16 +101,6 @@ public class ErrorsTag extends AbstractHtmlElementBodyTag implements BodyTag { } - /** - * Get the value for the HTML 'name' attribute. - *

Simply returns null because the 'name' attribute - * is not a validate attribute for the 'span' element. - */ - @Override - protected String getName() throws JspException { - return null; - } - /** * Get the value for the HTML 'id' attribute. *

Appends '.errors' to the value returned by {@link #getPropertyPath()} @@ -125,7 +116,17 @@ public class ErrorsTag extends AbstractHtmlElementBodyTag implements BodyTag { path = (String) this.pageContext.getAttribute( FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE); } - return path + ".errors"; + return StringUtils.deleteAny(path, "[]") + ".errors"; + } + + /** + * Get the value for the HTML 'name' attribute. + *

Simply returns null because the 'name' attribute + * is not a validate attribute for the 'span' element. + */ + @Override + protected String getName() throws JspException { + return null; } /**