1 19 20 package com.sslexplorer.input.tags; 21 22 import javax.servlet.jsp.JspException ; 23 24 import org.apache.struts.taglib.TagUtils; 25 import org.apache.struts.taglib.html.BaseFieldTag; 26 import org.apache.struts.util.MessageResources; 27 28 public class AbstractMultiFieldTag extends BaseFieldTag { 29 protected String targetTitleKey; 30 protected String addKey; 31 protected String removeKey; 32 protected String upKey; 33 protected String downKey; 34 protected String configureKey; 35 protected String configureOnClick; 36 protected boolean disabled; 37 protected boolean allowReordering; 38 39 42 protected static MessageResources messages = 43 MessageResources.getMessageResources( 44 "org.apache.struts.taglib.bean.LocalStrings"); 45 46 public AbstractMultiFieldTag() { 47 super(); 48 } 50 51 54 public String getTargetTitleKey() { 55 return targetTitleKey; 56 } 57 58 61 public String getAddKey() { 62 return addKey; 63 } 64 65 68 public String getDownKey() { 69 return downKey; 70 } 71 72 75 public void setDownKey(String downKey) { 76 this.downKey = downKey; 77 } 78 79 82 public String getUpKey() { 83 return upKey; 84 } 85 86 89 public void setUpKey(String upKey) { 90 this.upKey = upKey; 91 } 92 93 96 public void setAddKey(String addKey) { 97 this.addKey = addKey; 98 } 99 100 103 public String getRemoveKey() { 104 return removeKey; 105 } 106 107 110 public void setRemoveKey(String removeKey) { 111 this.removeKey = removeKey; 112 } 113 114 117 public void setTargetTitleKey(String targetTitleKey) { 118 this.targetTitleKey = targetTitleKey; 119 } 120 121 protected String prepareTargetTitle() throws JspException { 122 123 if(targetTitleKey != null) { 124 String targetTitle = 125 TagUtils.getInstance().message( 126 pageContext, 127 getBundle(), 128 getLocale(), 129 targetTitleKey, 130 new String [] { }); 131 132 if (targetTitle == null) { 133 JspException e = 134 new JspException ( 135 messages.getMessage("message.message", "\"" + targetTitleKey + "\"")); 136 TagUtils.getInstance().saveException(pageContext, e); 137 throw e; 138 } 139 return targetTitle; 140 } 141 return null; 142 } 143 144 protected String renderConfigureComponent() throws JspException { 145 StringBuffer results = new StringBuffer ("<input class=\"configure\" onclick=\""); 146 results.append(configureOnClick); 147 results.append("\" type=\"button\" value=\""); 148 results.append(prepareConfigure()); 149 results.append("\""); 150 results.append(prepareDisabled()); 151 results.append("/>"); 152 return results.toString(); 153 } 154 155 protected String renderUpComponent() throws JspException { 156 StringBuffer results = new StringBuffer ("<input class=\"multiUp\""); 157 results.append(prepareDisabled()); 158 results.append(" onclick=\"multiMoveUp("); 159 results.append("document.getElementById('"); 160 if (indexed) { 161 this.prepareIndex(results, name); 162 } 163 results.append(property); 164 results.append("'), document.getElementById('"); 165 results.append(prepareTargetId()); 166 results.append("'));\" type=\"button\" value=\""); 167 results.append(prepareUp()); 168 results.append("\"/>"); 169 return results.toString(); 170 } 171 172 protected String renderDownComponent() throws JspException { 173 StringBuffer results = new StringBuffer ("<input class=\"multiDown\""); 174 results.append(prepareDisabled()); 175 results.append(" onclick=\"multiMoveDown("); 176 results.append("document.getElementById('"); 177 if (indexed) { 178 this.prepareIndex(results, name); 179 } 180 results.append(property); 181 results.append("'), document.getElementById('"); 182 results.append(prepareTargetId()); 183 results.append("'));\" type=\"button\" value=\""); 184 results.append(prepareDown()); 185 results.append("\"/>"); 186 return results.toString(); 187 } 188 189 protected String prepareDisabled() { 190 if(isDisabled()) { 191 return " disabled=\"disabled\""; 192 } 193 else { 194 return ""; 195 } 196 } 197 198 protected String prepareConfigure() throws JspException { 199 200 if(addKey != null) { 201 String configure = 202 TagUtils.getInstance().message( 203 pageContext, 204 getBundle(), 205 getLocale(), 206 configureKey, 207 new String [] { }); 208 209 if (configureKey == null) { 210 JspException e = 211 new JspException ( 212 messages.getMessage("message.message", "\"" + addKey + "\"")); 213 TagUtils.getInstance().saveException(pageContext, e); 214 throw e; 215 } 216 return configure; 217 } 218 return ">>"; 219 } 220 221 protected String prepareAdd() throws JspException { 222 223 if(addKey != null) { 224 String add = 225 TagUtils.getInstance().message( 226 pageContext, 227 getBundle(), 228 getLocale(), 229 addKey, 230 new String [] { }); 231 232 if (addKey == null) { 233 JspException e = 234 new JspException ( 235 messages.getMessage("message.message", "\"" + addKey + "\"")); 236 TagUtils.getInstance().saveException(pageContext, e); 237 throw e; 238 } 239 return add; 240 } 241 return ">>"; 242 } 243 244 protected String prepareUp() throws JspException { 245 246 if(upKey != null) { 247 String up = 248 TagUtils.getInstance().message( 249 pageContext, 250 getBundle(), 251 getLocale(), 252 upKey, 253 new String [] { }); 254 255 if (upKey == null) { 256 JspException e = 257 new JspException ( 258 messages.getMessage("message.message", "\"" + upKey + "\"")); 259 TagUtils.getInstance().saveException(pageContext, e); 260 throw e; 261 } 262 return up; 263 } 264 return "Up"; 265 } 266 267 protected String prepareDown() throws JspException { 268 269 if(downKey != null) { 270 String down = 271 TagUtils.getInstance().message( 272 pageContext, 273 getBundle(), 274 getLocale(), 275 downKey, 276 new String [] { }); 277 278 if (downKey == null) { 279 JspException e = 280 new JspException ( 281 messages.getMessage("message.message", "\"" + downKey + "\"")); 282 TagUtils.getInstance().saveException(pageContext, e); 283 throw e; 284 } 285 return down; 286 } 287 return "Down"; 288 } 289 290 protected String prepareRemove() throws JspException { 291 292 if(removeKey != null) { 293 String remove = 294 TagUtils.getInstance().message( 295 pageContext, 296 getBundle(), 297 getLocale(), 298 removeKey, 299 new String [] { }); 300 301 if (remove == null) { 302 JspException e = 303 new JspException ( 304 messages.getMessage("message.message", "\"" + removeKey + "\"")); 305 TagUtils.getInstance().saveException(pageContext, e); 306 throw e; 307 } 308 return remove; 309 } 310 return "<<"; 311 } 312 313 protected String prepareTargetId() throws JspException { 314 StringBuffer results = new StringBuffer ("targetValues_"); 315 if(indexed) { 316 prepareIndex(results, name); 317 } 318 results.append(property); 319 return results.toString(); 320 } 321 322 325 public void setConfigureKey(String configureKey) { 326 this.configureKey = configureKey; 327 } 328 329 332 public void setConfigureOnClick(String configureOnClick) { 333 this.configureOnClick = configureOnClick; 334 } 335 336 public void setDisabled(boolean disabled) { 337 this.disabled = disabled; 338 } 339 340 public boolean isDisabled() { 341 return disabled; 342 } 343 344 public boolean isAllowReordering() { 345 return allowReordering; 346 } 347 348 public void setAllowReordering(boolean allowReordering) { 349 this.allowReordering = allowReordering; 350 } 351 352 355 public void release() { 356 super.release(); 357 targetTitleKey = null; 358 addKey = null; 359 removeKey = null; 360 upKey = null; 361 downKey = null; 362 configureKey = null; 363 configureOnClick = null; 364 disabled = false; 365 allowReordering = false; 366 } 367 } 368 | Popular Tags |