1 7 package com.inversoft.verge.mvc.view.jsp.html; 8 9 10 import java.io.IOException ; 11 12 import javax.servlet.jsp.JspException ; 13 14 import org.apache.log4j.Logger; 15 16 import com.inversoft.util.ObjectTools; 17 import com.inversoft.verge.mvc.view.HtmlConstants; 18 import com.inversoft.verge.mvc.view.HtmlViewToolkit; 19 import com.inversoft.verge.mvc.view.jsp.JspTools; 20 21 22 28 public class OptionTag extends HtmlBaseTag { 29 30 33 private static final Logger logger = Logger.getLogger(OptionTag.class); 34 35 private Object value; 36 protected Object localValue; 37 private String label; 38 protected String localLabel; 39 private Boolean selected; 40 protected Boolean localSelected; 41 Boolean disabled; 42 protected SelectTag selectParent; 43 44 45 50 public Object getValue() { 51 return value; 52 } 53 54 59 public void setValue(Object value) { 60 this.value = value; 61 } 62 63 68 public Boolean getSelected() { 69 return selected; 70 } 71 72 77 public void setSelected(Boolean selected) { 78 this.selected = selected; 79 } 80 81 86 public Boolean getDisabled() { 87 return disabled; 88 } 89 90 95 public void setDisabled(Boolean disabled) { 96 this.disabled = disabled; 97 } 98 99 104 public String getLabel() { 105 return label; 106 } 107 108 113 public void setLabel(String label) { 114 this.label = label; 115 } 116 117 122 protected void initialize() throws JspException { 123 super.initialize(); 124 125 localLabel = label; 126 localValue = value; 127 localSelected = selected; 128 129 if (!JspTools.JSP_20) { 130 localLabel = (String ) JspTools.expand("label", label, String .class, 131 this, pageContext); 132 133 if (value instanceof String ) { 134 localValue = JspTools.expand("value", (String ) value, Object .class, 135 this, pageContext); 136 } 137 } 138 139 if (disabled != null && disabled.booleanValue()) { 140 singleAttrs.add(HtmlConstants.DISABLED); 141 } 142 143 attributes.put(HtmlConstants.LABEL, localLabel); 144 145 selectParent = (SelectTag) findAncestorWithClass(this, SelectTag.class); 147 if (selectParent == null) { 148 throw new JspException ("Option tags must be imbedded in select tags"); 149 } 150 151 Object parentValue = selectParent.getLocalValue(); 152 if (parentValue != null) { 153 localSelected = 155 new Boolean (ObjectTools.areObjectsEqual(localValue, parentValue)); 156 } 157 } 158 159 167 public int doStartTag() throws JspException { 168 169 initialize(); 170 171 StringBuffer buf = new StringBuffer (); 172 createOptionTag(buf, getId(), localValue, localSelected); 173 174 if (logger.isDebugEnabled()) { 175 logger.debug("The option tag: " + buf.toString()); 176 } 177 178 try { 179 pageContext.getOut().print(buf.toString()); 180 } catch (IOException ioe) { 181 throw new JspException (ioe.toString()); 182 } 183 184 return EVAL_BODY_INCLUDE; 185 } 186 187 192 public int doEndTag() throws JspException { 193 try { 194 pageContext.getOut().print(HtmlConstants.OPTION_END_TAG); 195 } catch (IOException ioe) { 196 throw new JspException (ioe.toString()); 197 } 198 199 selected = null; 202 203 return EVAL_PAGE; 204 } 205 206 214 protected void createOptionTag(StringBuffer buf, String id, Object value, 215 Boolean selected) { 216 boolean selectedBool = (selected == null) ? false : selected.booleanValue(); 217 String valueStr = ObjectTools.toString(value); 218 HtmlViewToolkit.createOptionStartTag(buf, valueStr, selectedBool, 219 attributes, singleAttrs); 220 } 221 } | Popular Tags |