1 18 19 package org.apache.struts.taglib.logic; 20 21 import java.util.Iterator ; 22 23 import javax.servlet.jsp.JspException ; 24 25 import org.apache.struts.Globals; 26 import org.apache.struts.action.ActionMessages; 27 import org.apache.struts.taglib.TagUtils; 28 29 38 public class MessagesPresentTag extends ConditionalTagBase { 39 40 44 protected String message = null; 45 46 47 public MessagesPresentTag() { 48 name = Globals.ERROR_KEY; 49 } 50 51 public String getMessage() { 52 return (this.message); 53 } 54 55 public void setMessage(String message) { 56 this.message = message; 57 } 58 59 67 protected boolean condition() throws JspException { 68 69 return (condition(true)); 70 71 } 72 73 74 84 protected boolean condition(boolean desired) throws JspException { 85 ActionMessages am = null; 86 87 String key = name; 88 if (message != null && "true".equalsIgnoreCase(message)){ 89 key = Globals.MESSAGE_KEY; 90 } 91 92 try { 93 am = TagUtils.getInstance().getActionMessages(pageContext, key); 94 95 } catch (JspException e) { 96 TagUtils.getInstance().saveException(pageContext, e); 97 throw e; 98 } 99 100 Iterator iterator = (property == null) ? am.get() : am.get(property); 101 102 return (iterator.hasNext() == desired); 103 104 } 105 106 109 public void release() { 110 super.release(); 111 name = Globals.ERROR_KEY; 112 message = null; 113 } 114 115 } 116 | Popular Tags |