1 package com.jcorporate.expresso.services.taglib; 2 3 66 67 import com.jcorporate.expresso.core.controller.Input; 68 import com.jcorporate.expresso.core.dbobj.ValidValue; 69 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 70 import org.apache.log4j.Logger; 71 72 import javax.servlet.jsp.JspException ; 73 import javax.servlet.jsp.tagext.TagSupport ; 74 import java.io.IOException ; 75 import java.util.Iterator ; 76 import java.util.List ; 77 import java.util.Vector ; 78 79 88 public class SelectOptions extends TagSupport { 89 public SelectOptions() { 90 } 91 92 private static final Logger log = Logger.getLogger(SelectOptions.class); 93 94 97 private String value; 98 99 104 public String getValue() { 105 return value; 106 } 107 108 113 public void setValue(String value) { 114 this.value = value; 115 } 116 117 122 public int doEndTag() throws javax.servlet.jsp.JspException { 123 ELTagSupport support = ELTagSupport.getInstance(); 124 Input result = (Input) support.evaluate("value", this.getValue(), 125 Input.class, 126 this, this.pageContext); 127 128 if (result == null) { 129 throw new JspException ("Unable to find Input with expression: " + this.getValue()); 130 } 131 132 String writeValue; 133 FastStringBuffer fsb = FastStringBuffer.getInstance(); 134 List defaultValues = result.getDefaultValueList(); 135 136 try { 137 Vector vec = result.getValidValues(); 138 if (vec != null) { 139 int size = vec.size(); 140 for (int i = 0; i < size; i++) { 141 ValidValue vv = (ValidValue) vec.get(i); 142 boolean selected = false; 143 String value = vv.getValue(); 144 for (Iterator iterator = defaultValues.iterator(); iterator.hasNext();) { 145 String def = (String ) iterator.next(); 146 if (value.equals(def)) { 147 selected = true; 148 break; 149 } 150 } 151 152 153 fsb.append("<option value=\""); 154 fsb.append(vv.getValue()); 155 fsb.append("\""); 156 if (selected) { 157 fsb.append(" selected "); 158 } 159 fsb.append(">"); 160 fsb.append(vv.getDescription()); 161 fsb.append("</option>\n"); 162 } 163 } else { 164 System.err.println("Cannot find valid values for input: " + this.getValue()); 166 } 167 } finally { 168 writeValue = fsb.toString(); 169 fsb.release(); 170 } 171 172 try { 173 pageContext.getOut().write(writeValue); 174 } catch (IOException ex1) { 175 log.error("I/O exception writing output value", ex1); 176 } 177 178 return EVAL_PAGE; 179 } 180 181 } | Popular Tags |