1 18 19 package org.apache.struts.taglib.bean; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.tagext.TagSupport ; 23 24 import org.apache.struts.util.MessageResources; 25 import org.apache.struts.taglib.TagUtils; 26 27 33 public class ParameterTag extends TagSupport { 34 35 37 41 protected String id = null; 42 43 public String getId() { 44 return (this.id); 45 } 46 47 public void setId(String id) { 48 this.id = id; 49 } 50 51 54 protected static MessageResources messages = 55 MessageResources.getMessageResources( 56 "org.apache.struts.taglib.bean.LocalStrings"); 57 58 62 protected String multiple = null; 63 64 public String getMultiple() { 65 return (this.multiple); 66 } 67 68 public void setMultiple(String multiple) { 69 this.multiple = multiple; 70 } 71 72 75 protected String name = null; 76 77 public String getName() { 78 return (this.name); 79 } 80 81 public void setName(String name) { 82 this.name = name; 83 } 84 85 89 protected String value = null; 90 91 public String getValue() { 92 return (this.value); 93 } 94 95 public void setValue(String value) { 96 this.value = value; 97 } 98 99 101 106 public int doStartTag() throws JspException { 107 108 if (multiple == null) { 110 String value = pageContext.getRequest().getParameter(name); 111 if ((value == null) && (this.value != null)) { 112 value = this.value; 113 } 114 115 if (value == null) { 116 JspException e = 117 new JspException (messages.getMessage("parameter.get", name)); 118 TagUtils.getInstance().saveException(pageContext, e); 119 throw e; 120 } 121 122 pageContext.setAttribute(id, value); 123 return (SKIP_BODY); 124 } 125 126 String values[] = pageContext.getRequest().getParameterValues(name); 128 if ((values == null) || (values.length == 0)) { 129 if (this.value != null) { 130 values = new String [] { this.value }; 131 } 132 } 133 134 if ((values == null) || (values.length == 0)) { 135 JspException e = 136 new JspException (messages.getMessage("parameter.get", name)); 137 TagUtils.getInstance().saveException(pageContext, e); 138 throw e; 139 } 140 141 pageContext.setAttribute(id, values); 142 return (SKIP_BODY); 143 144 } 145 146 149 public void release() { 150 151 super.release(); 152 id = null; 153 multiple = null; 154 name = null; 155 value = null; 156 157 } 158 159 } 160 | Popular Tags |