2
* Copyright 2002,2004 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package org.apache.struts.faces.taglib;
20
import java.util.Locale;
22
import javax.faces.context.FacesContext;
24
import javax.servlet.jsp.PageContext;
25
import javax.servlet.jsp.tagext.TagSupport;
27
import org.apache.struts.Globals;
28
import org.apache.struts.faces.util.MessagesMap;
29
import org.apache.struts.util.MessageResources;
33
* <p>Tag that exposes a specified <code>MessageResources</code> instance
34
* as <code>Map</code>, so that the embedded messages may be retrieved via
35
* value binding expressions.</p>
38
public class LoadMessagesTag extends TagSupport {
41
// ---------------------------------------------------------- Tag Attributes
45
* <p>The name of the <code>MessageResources</code> to expose, or
46
* <code>null</code> for the default <code>MessageResources</code>
47
* for this application module.</p>
49
private String messages = null;
50
public void setMessages(String messages) {
51
this.messages = messages;
56
* <p>The request attribute key under which a <code>Map</code>
57
* will be exposed.</p>
59
private String var = null;
60
public void setVar(String var) {
65
// ------------------------------------------------------------- Tag Methods
69
* <p>Expose a <code>Map</code> wrapping the specified
70
* <code>MessageResources</code> instance, for the <code>Locale</code>
71
* specified in the view root component of the current view.</p>
73
public int doStartTag() {
75
// Acquire the Locale to be wrapped
77
FacesContext.getCurrentInstance().getViewRoot().getLocale();
79
// Acquire the MessageResources to be wrapped
80
MessageResources messages = null;
81
if (this.messages == null) {
82
messages = (MessageResources)
83
pageContext.getAttribute(Globals.MESSAGES_KEY,
84
PageContext.REQUEST_SCOPE);
85
if (messages == null) {
86
messages = (MessageResources)
87
pageContext.getAttribute(Globals.MESSAGES_KEY,
88
PageContext.APPLICATION_SCOPE);
91
messages = (MessageResources)
92
pageContext.getAttribute(this.messages,
93
PageContext.APPLICATION_SCOPE);
96
// Expose a Map instance under the specified request attribute key
97
pageContext.setAttribute(var,
98
new MessagesMap(messages, locale),
99
PageContext.REQUEST_SCOPE);
101
// Skip the body of this tag (if any)
108
* <p>Release any resources allocated by this tag instance.</p>
110
public void release() {
112
this.messages = null;