I wanted to localize
direct content when using templates such as the title of a page. I modified
the bean:message tag so it would read its key from the tag body if it wasn't
specified as an attribute. Is there a better way to internationalize direct
content with templates? Are there any other reasons that someone would want to
get the bean:message key from the body of the tag? Are there reasons why this
doesn't make sense?
<bean:message>
<template:get name="titlekey" flush="false"/>
</bean:message>
<template:get name="titlekey" flush="false"/>
</bean:message>
Below are the diffs
to the files I modified and I attached the MessageTag class. If these changes
aren't worthwhile then I can wait until localization is built into the templates
framework.
Thanks,
Hal
src/doc/struts-bean.xml
407c407
< <bodycontent>empty</bodycontent>
---
> <bodycontent>JSP</bodycontent>
473c473
< <required>true</required>
---
> <required>false</required>
< <bodycontent>empty</bodycontent>
---
> <bodycontent>JSP</bodycontent>
473c473
< <required>true</required>
---
> <required>false</required>
src/share/org/apache/struts/taglib/bean/MessagesTag.java
71c71
< import javax.servlet.jsp.tagext.TagSupport;
---
> import javax.servlet.jsp.tagext.BodyTagSupport;
88c88
< public class MessageTag extends TagSupport {
---
> public class MessageTag extends BodyTagSupport {
210a211,214
> /**
> * The body text which will be used as the key if key attribute not spec
> */
> protected String text = null;
228a233,235
> // Do nothing until doEndTag() is called
> return (EVAL_BODY_TAG);
> }
229a237,253
> /**
> * Process the body text of this tag (if any).
> *
> * @exception JspException if a JSP exception has occurred
> */
> public int doAfterBody() throws JspException {
> String text = bodyContent.getString();
> if (text != null) {
> text = text.trim();
> if (text.length() > 0)
> this.text = text;
> }
> return (SKIP_BODY);
> }
>
>
> public int doEndTag() throws JspException {
237a262,270
> if (key == null)
> {
> if (text == null )
> {
> return (EVAL_PAGE);
> }
> key = text;
> }
>
251,253c284,285
< // Continue processing this page
< return (SKIP_BODY);
<
---
> // Continue evaluating this page
> return (EVAL_PAGE);
256d287
<
261d291
< import javax.servlet.jsp.tagext.TagSupport;
---
> import javax.servlet.jsp.tagext.BodyTagSupport;
88c88
< public class MessageTag extends TagSupport {
---
> public class MessageTag extends BodyTagSupport {
210a211,214
> /**
> * The body text which will be used as the key if key attribute not spec
> */
> protected String text = null;
228a233,235
> // Do nothing until doEndTag() is called
> return (EVAL_BODY_TAG);
> }
229a237,253
> /**
> * Process the body text of this tag (if any).
> *
> * @exception JspException if a JSP exception has occurred
> */
> public int doAfterBody() throws JspException {
> String text = bodyContent.getString();
> if (text != null) {
> text = text.trim();
> if (text.length() > 0)
> this.text = text;
> }
> return (SKIP_BODY);
> }
>
>
> public int doEndTag() throws JspException {
237a262,270
> if (key == null)
> {
> if (text == null )
> {
> return (EVAL_PAGE);
> }
> key = text;
> }
>
251,253c284,285
< // Continue processing this page
< return (SKIP_BODY);
<
---
> // Continue evaluating this page
> return (EVAL_PAGE);
256d287
<
261d291