You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ni...@apache.org on 2005/03/28 19:38:34 UTC
svn commit: r159269 - in struts/taglib/trunk: doc/userGuide/struts-html.xml
src/java/org/apache/struts/taglib/TagUtils.java
src/java/org/apache/struts/taglib/html/ErrorsTag.java
src/java/org/apache/struts/taglib/html/JavascriptValidatorTag.java
src/java/org/apache/struts/taglib/html/MessagesTag.java
Author: niallp
Date: Mon Mar 28 09:38:31 2005
New Revision: 159269
URL: http://svn.apache.org/viewcvs?view=rev&rev=159269
Log:
Bug 21760 Validator support for non-default Resource bundles reported by Adam Kramer
Modified:
struts/taglib/trunk/doc/userGuide/struts-html.xml
struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ErrorsTag.java
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/JavascriptValidatorTag.java
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java
Modified: struts/taglib/trunk/doc/userGuide/struts-html.xml
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/doc/userGuide/struts-html.xml?view=diff&r1=159268&r2=159269
==============================================================================
--- struts/taglib/trunk/doc/userGuide/struts-html.xml (original)
+++ struts/taglib/trunk/doc/userGuide/struts-html.xml Mon Mar 28 09:38:31 2005
@@ -3676,6 +3676,17 @@
</p>
</info>
</attribute>
+ <attribute>
+ <name>bundle</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <info>
+ The servlet context attributes key for the MessageResources
+ instance to use. If not specified, defaults to the
+ application resources configured for our action servlet.
+ </info>
+ <since>Struts 1.2.7</since>
+ </attribute>
</tag>
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java?view=diff&r1=159268&r2=159269
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java Mon Mar 28 09:38:31 2005
@@ -1131,7 +1131,7 @@
* @return MessageResources The bundle's resources stored in some scope.
* @throws JspException if the MessageResources object could not be found.
*/
- private MessageResources retrieveMessageResources(
+ public MessageResources retrieveMessageResources(
PageContext pageContext,
String bundle,
boolean checkPageScope)
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ErrorsTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ErrorsTag.java?view=diff&r1=159268&r2=159269
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ErrorsTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ErrorsTag.java Mon Mar 28 09:38:31 2005
@@ -245,13 +245,17 @@
results.append(message);
}
- message =
- TagUtils.getInstance().message(
- pageContext,
- bundle,
- locale,
- report.getKey(),
- report.getValues());
+ if (report.isResource()) {
+ message =
+ TagUtils.getInstance().message(
+ pageContext,
+ bundle,
+ locale,
+ report.getKey(),
+ report.getValues());
+ } else {
+ message = report.getKey();
+ }
if (message != null) {
results.append(message);
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/JavascriptValidatorTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/JavascriptValidatorTag.java?view=diff&r1=159268&r2=159269
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/JavascriptValidatorTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/JavascriptValidatorTag.java Mon Mar 28 09:38:31 2005
@@ -27,12 +27,15 @@
import java.util.Locale;
import java.util.Map;
+import javax.servlet.ServletContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.Field;
+import org.apache.commons.validator.Msg;
import org.apache.commons.validator.Form;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.ValidatorResources;
@@ -322,6 +325,20 @@
}
/**
+ * Sets the servlet context attribute key for our resources.
+ */
+ public String getBundle() {
+ return bundle;
+ }
+
+ /**
+ * Gets the servlet context attribute key for our resources.
+ */
+ public void setBundle(String bundle) {
+ this.bundle = bundle;
+ }
+
+ /**
* Render the JavaScript for to perform validations based on the form name.
*
* @exception JspException if a JSP exception has occurred
@@ -408,10 +425,11 @@
StringBuffer results = new StringBuffer();
- MessageResources messages =
- (MessageResources) pageContext.getAttribute(
- bundle + config.getPrefix(),
- PageContext.APPLICATION_SCOPE);
+ MessageResources messages =
+ TagUtils.getInstance().retrieveMessageResources(pageContext, bundle, true);
+
+ HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
+ ServletContext application = pageContext.getServletContext();
List actions = this.createActionList(resources, form);
@@ -459,7 +477,12 @@
continue;
}
- String message = Resources.getMessage(messages, locale, va, field);
+ String message = Resources.getMessage(application,
+ request,
+ messages,
+ locale,
+ va,
+ field);
message = (message != null) ? message : "";
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java?view=diff&r1=159268&r2=159269
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java Mon Mar 28 09:38:31 2005
@@ -201,13 +201,17 @@
}
ActionMessage report = (ActionMessage) this.iterator.next();
- String msg =
- TagUtils.getInstance().message(
- pageContext,
- bundle,
- locale,
- report.getKey(),
- report.getValues());
+ String msg = null;
+ if (report.isResource()) {
+ msg = TagUtils.getInstance().message(
+ pageContext,
+ bundle,
+ locale,
+ report.getKey(),
+ report.getValues());
+ } else {
+ msg = report.getKey();
+ }
if (msg == null) {
pageContext.removeAttribute(id);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org