1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.faces.renderer;
23
24 import java.util.Locale;
25
26 import org.apache.struts.Globals;
27 import org.apache.struts.faces.component.LoadMessagesComponent;
28 import org.apache.struts.faces.util.MessagesMap;
29 import org.apache.struts.faces.util.Utils;
30 import org.apache.struts.util.MessageResources;
31
32 import jakarta.faces.component.UIComponent;
33 import jakarta.faces.context.ExternalContext;
34 import jakarta.faces.context.FacesContext;
35
36
37
38
39
40
41
42 public class LoadMessagesRenderer extends AbstractRenderer {
43
44
45
46
47
48
49
50 public void encodeBegin(FacesContext context, UIComponent component) {
51
52 final LoadMessagesComponent comp = (LoadMessagesComponent)
53 component;
54
55 final ExternalContext econtext = context.getExternalContext();
56
57
58 final Locale locale =
59 FacesContext.getCurrentInstance().getViewRoot().getLocale();
60
61
62 MessageResources messages = null;
63 if (comp.getMessages() == null) {
64 messages = Utils.getMapValue(MessageResources.class,
65 econtext.getRequestMap(), Globals.MESSAGES_KEY);
66 if (messages == null) {
67 messages = Utils.getMapValue(MessageResources.class,
68 econtext.getApplicationMap(), Globals.MESSAGES_KEY);
69 }
70 } else {
71 messages = Utils.getMapValue(MessageResources.class,
72 econtext.getApplicationMap(), comp.getMessages());
73 }
74
75
76 econtext.getRequestMap()
77 .put(comp.getVar(), new MessagesMap(messages, locale));
78 }
79 }