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.struts2.components;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.struts2.views.annotations.StrutsTag;
28 import org.apache.struts2.views.annotations.StrutsTagAttribute;
29 import org.apache.commons.lang.xwork.StringUtils;
30
31 import com.opensymphony.xwork2.util.ValueStack;
32
33 import java.util.List;
34 import java.util.Collection;
35
36 /***
37 * <!-- START SNIPPET: javadoc -->
38 *
39 * Render action messages if they exists, specific rendering layout depends on the
40 * theme itself. Empty (null or blank string) messages will not be printed. The action message
41 * strings will be html escaped by default.
42 *
43 * <!-- END SNIPPET: javadoc -->
44 *
45 * <p/> <b>Examples</b>
46 *
47 * <pre>
48 * <!-- START SNIPPET: example -->
49 * <s:actionmessage />
50 * <s:form .... >
51 * ....
52 * </s:form>
53 * <!-- END SNIPPET: example -->
54 * </pre>
55 *
56 */
57 @StrutsTag(name="actionmessage", tldBodyContent="empty", tldTagClass="org.apache.struts2.views.jsp.ui.ActionMessageTag", description="Render action messages if they exists")
58 public class ActionMessage extends UIBean {
59
60 private static final String TEMPLATE = "actionmessage";
61 protected boolean escape = true;
62
63 public ActionMessage(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
64 super(stack, request, response);
65 }
66
67 protected String getDefaultTemplate() {
68 return TEMPLATE;
69 }
70
71 protected void evaluateExtraParams() {
72 boolean isEmptyList = true;
73 Collection<String> actionMessages = (List) findValue("actionMessages");
74 if (actionMessages != null) {
75 for (String message : actionMessages) {
76 if (StringUtils.isNotBlank(message)) {
77 isEmptyList = false;
78 break;
79 }
80 }
81 }
82
83 addParameter("isEmptyList", isEmptyList);
84 addParameter("escape", escape);
85 }
86
87 @StrutsTagAttribute(description=" Whether to escape HTML", type="Boolean", defaultValue="true")
88 public void setEscape(boolean escape) {
89 this.escape = escape;
90 }
91 }