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.Collection;
34 import java.util.List;
35
36 /***
37 * <!-- START SNIPPET: javadoc -->
38 *
39 * Render action errors if they exists the specific layout of the rendering depends on
40 * the theme itself. Empty (null or blank string) errors will not be printed. The action error
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 *
50 * <s:actionerror />
51 * <s:form .... >
52 * ....
53 * </s:form>
54 *
55 * <!-- END SNIPPET: example -->
56 * </pre>
57 *
58 */
59 @StrutsTag(name="actionerror", tldBodyContent="empty", tldTagClass="org.apache.struts2.views.jsp.ui.ActionErrorTag", description="Render action errors if they exists")
60 public class ActionError extends UIBean {
61
62 public static final String TEMPLATE = "actionerror";
63 private boolean escape = true;
64
65 public ActionError(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
66 super(stack, request, response);
67 }
68
69 protected String getDefaultTemplate() {
70 return TEMPLATE;
71 }
72
73 protected void evaluateExtraParams() {
74 boolean isEmptyList = true;
75 Collection<String> actionMessages = (List) findValue("actionErrors");
76 if (actionMessages != null) {
77 for (String message : actionMessages) {
78 if (StringUtils.isNotBlank(message)) {
79 isEmptyList = false;
80 break;
81 }
82 }
83 }
84
85 addParameter("isEmptyList", isEmptyList);
86 addParameter("escape", escape);
87 }
88
89 @StrutsTagAttribute(description=" Whether to escape HTML", type="Boolean", defaultValue="true")
90 public void setEscape(boolean escape) {
91 this.escape = escape;
92 }
93 }