1 18 package org.apache.beehive.netui.tags.html; 19 20 import org.apache.beehive.netui.util.internal.InternalStringBuilder; 21 22 import org.apache.beehive.netui.util.Bundle; 23 import org.apache.beehive.netui.pageflow.internal.InternalUtils; 24 import org.apache.struts.Globals; 25 import org.apache.struts.action.ActionMessage; 26 import org.apache.struts.action.ActionMessages; 27 import org.apache.struts.util.RequestUtils; 28 29 import javax.servlet.jsp.JspException ; 30 import javax.servlet.jsp.PageContext ; 31 import java.util.Iterator ; 32 33 65 public class Error extends ErrorBaseTag 66 { 67 private String _key = null; 69 72 public String getTagName() 73 { 74 return "Error"; 75 } 76 77 86 public void setKey(String key) 87 throws JspException  88 { 89 _key = setRequiredValueAttribute(key, "key"); 90 } 91 92 96 public void doTag() 97 throws JspException  98 { 99 102 PageContext pageContext = getPageContext(); 103 104 ActionMessages errors = null; 106 try { 107 errors = RequestUtils.getActionMessages(pageContext, Globals.ERROR_KEY); 108 } 109 catch (JspException e) { 110 RequestUtils.saveException(pageContext, e); 111 throw e; 112 } 113 114 if ((errors == null) || errors.isEmpty()) { 116 if (hasErrors()) 117 reportErrors(); 118 return; 119 } 120 121 String qualifiedBundle = InternalUtils.getQualifiedBundleName(_bundleName, pageContext.getRequest()); 122 123 boolean prefixPresent = false; 124 boolean suffixPresent = false; 125 String locale = _locale; 126 127 if (!isMissingUserDefaultMessages(pageContext)) { 128 try { 129 prefixPresent = 131 RequestUtils.present(pageContext, qualifiedBundle, locale, "error.prefix"); 132 suffixPresent = 133 RequestUtils.present(pageContext, qualifiedBundle, locale, "error.suffix"); 134 } 135 catch (JspException e) { 136 String s = Bundle.getString("Tags_ErrorsException", new Object []{e.getMessage()}); 137 registerTagError(s, null); 138 reportErrors(); 139 return; 140 } 141 } 142 143 InternalStringBuilder results = new InternalStringBuilder(128); 145 146 String message = null; 147 Iterator reports = null; 148 reports = errors.get(_key); 149 150 while (reports.hasNext()) { 151 ActionMessage report = (ActionMessage) reports.next(); 152 if (prefixPresent) { 153 message = RequestUtils.message(pageContext, qualifiedBundle, locale, "error.prefix"); 154 results.append(message); 155 } 156 157 message = getErrorMessage(report, qualifiedBundle); 158 159 if (message != null) { 160 results.append(message); 161 results.append("\r\n"); 162 } 163 if (suffixPresent) { 164 165 message = RequestUtils.message(pageContext, qualifiedBundle, locale, "error.suffix"); 166 results.append(message); 167 } 168 } 169 170 write(results.toString()); 171 172 if (hasErrors()) 174 reportErrors(); 175 } 176 } 177 | Popular Tags |