1 24 package org.ofbiz.widget.form; 25 26 import java.math.BigDecimal ; 27 import java.text.NumberFormat ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.LinkedList ; 31 import java.util.List ; 32 import java.util.Locale ; 33 import java.util.Map ; 34 import java.util.StringTokenizer ; 35 36 import javolution.util.FastList; 37 38 import org.ofbiz.base.util.BshUtil; 39 import org.ofbiz.base.util.Debug; 40 import org.ofbiz.base.util.GeneralException; 41 import org.ofbiz.base.util.ObjectType; 42 import org.ofbiz.base.util.UtilDateTime; 43 import org.ofbiz.base.util.UtilMisc; 44 import org.ofbiz.base.util.UtilValidate; 45 import org.ofbiz.base.util.UtilXml; 46 import org.ofbiz.base.util.UtilFormatOut; 47 import org.ofbiz.base.util.collections.FlexibleMapAccessor; 48 import org.ofbiz.base.util.collections.MapStack; 49 import org.ofbiz.base.util.string.FlexibleStringExpander; 50 import org.ofbiz.entity.GenericDelegator; 51 import org.ofbiz.entity.GenericEntityException; 52 import org.ofbiz.entity.GenericValue; 53 import org.ofbiz.entity.condition.EntityCondition; 54 import org.ofbiz.entity.condition.EntityConditionList; 55 import org.ofbiz.entity.condition.EntityOperator; 56 import org.ofbiz.entity.finder.EntityFinderUtil; 57 import org.ofbiz.entity.model.ModelEntity; 58 import org.ofbiz.entity.model.ModelField; 59 import org.ofbiz.entity.util.EntityUtil; 60 import org.ofbiz.service.GenericServiceException; 61 import org.ofbiz.service.LocalDispatcher; 62 import org.ofbiz.service.ModelParam; 63 import org.ofbiz.service.ModelService; 64 import org.w3c.dom.Element ; 65 66 import bsh.EvalError; 67 import bsh.Interpreter; 68 69 77 public class ModelFormField { 78 79 public static final String module = ModelFormField.class.getName(); 80 81 protected ModelForm modelForm; 82 83 protected String name; 84 protected FlexibleMapAccessor mapAcsr; 85 protected String entityName; 86 protected String serviceName; 87 protected FlexibleMapAccessor entryAcsr; 88 protected String parameterName; 89 protected String fieldName; 90 protected String attributeName; 91 protected FlexibleStringExpander title; 92 protected FlexibleStringExpander tooltip; 93 protected String titleAreaStyle; 94 protected String widgetAreaStyle; 95 protected String titleStyle; 96 protected String widgetStyle; 97 protected String tooltipStyle; 98 protected String requiredFieldStyle; 99 protected Integer position = null; 100 protected String redWhen; 101 protected String event; 102 protected String action; 103 protected FlexibleStringExpander useWhen; 104 105 protected FieldInfo fieldInfo = null; 106 protected String idName; 107 protected boolean separateColumn = false; 108 protected boolean requiredField = false; 109 protected String headerLink; 110 protected String headerLinkStyle; 111 112 114 public ModelFormField(ModelForm modelForm) { 115 this.modelForm = modelForm; 116 } 117 118 119 public ModelFormField(Element fieldElement, ModelForm modelForm) { 120 this.modelForm = modelForm; 121 this.name = fieldElement.getAttribute("name"); 122 this.setMapName(fieldElement.getAttribute("map-name")); 123 this.entityName = fieldElement.getAttribute("entity-name"); 124 this.serviceName = fieldElement.getAttribute("service-name"); 125 this.setEntryName(UtilXml.checkEmpty(fieldElement.getAttribute("entry-name"), this.name)); 126 this.parameterName = UtilXml.checkEmpty(fieldElement.getAttribute("parameter-name"), this.name); 127 this.fieldName = UtilXml.checkEmpty(fieldElement.getAttribute("field-name"), this.name); 128 this.attributeName = UtilXml.checkEmpty(fieldElement.getAttribute("attribute-name"), this.name); 129 this.setTitle(fieldElement.hasAttribute("title")?fieldElement.getAttribute("title"):null); 130 this.setTooltip(fieldElement.getAttribute("tooltip")); 131 this.titleAreaStyle = fieldElement.getAttribute("title-area-style"); 132 this.widgetAreaStyle = fieldElement.getAttribute("widget-area-style"); 133 this.titleStyle = fieldElement.getAttribute("title-style"); 134 this.widgetStyle = fieldElement.getAttribute("widget-style"); 135 this.tooltipStyle = fieldElement.getAttribute("tooltip-style"); 136 this.requiredFieldStyle = fieldElement.getAttribute("required-field-style"); 137 this.redWhen = fieldElement.getAttribute("red-when"); 138 this.event = fieldElement.getAttribute("event"); 139 this.action = fieldElement.getAttribute("action"); 140 this.setUseWhen(fieldElement.getAttribute("use-when")); 141 this.idName = fieldElement.getAttribute("id-name"); 142 String sepColumns = fieldElement.getAttribute("separate-column"); 143 if (sepColumns != null && sepColumns.equalsIgnoreCase("true")) 144 separateColumn = true; 145 this.requiredField = "true".equals(fieldElement.getAttribute("required-field")); 146 this.headerLink = fieldElement.getAttribute("header-link"); 147 this.headerLinkStyle = fieldElement.getAttribute("header-link-style"); 148 149 150 String positionStr = fieldElement.getAttribute("position"); 151 try { 152 if (positionStr != null && positionStr.length() > 0) { 153 position = Integer.valueOf(positionStr); 154 } 155 } catch (Exception e) { 156 Debug.logError( 157 e, 158 "Could not convert position attribute of the field element to an integer: [" + positionStr + "], using the default of the form renderer", 159 module); 160 } 161 162 Element subElement = UtilXml.firstChildElement(fieldElement); 164 if (subElement != null) { 165 String subElementName = subElement.getTagName(); 166 if (Debug.verboseOn()) 167 Debug.logVerbose("Processing field " + this.name + " with type info tag " + subElementName, module); 168 169 if (UtilValidate.isEmpty(subElementName)) { 170 this.fieldInfo = null; 171 this.induceFieldInfo(null); } else if ("display".equals(subElementName)) { 173 this.fieldInfo = new DisplayField(subElement, this); 174 } else if ("display-entity".equals(subElementName)) { 175 this.fieldInfo = new DisplayEntityField(subElement, this); 176 } else if ("hyperlink".equals(subElementName)) { 177 this.fieldInfo = new HyperlinkField(subElement, this); 178 } else if ("text".equals(subElementName)) { 179 this.fieldInfo = new TextField(subElement, this); 180 } else if ("textarea".equals(subElementName)) { 181 this.fieldInfo = new TextareaField(subElement, this); 182 } else if ("date-time".equals(subElementName)) { 183 this.fieldInfo = new DateTimeField(subElement, this); 184 } else if ("drop-down".equals(subElementName)) { 185 this.fieldInfo = new DropDownField(subElement, this); 186 } else if ("check".equals(subElementName)) { 187 this.fieldInfo = new CheckField(subElement, this); 188 } else if ("radio".equals(subElementName)) { 189 this.fieldInfo = new RadioField(subElement, this); 190 } else if ("submit".equals(subElementName)) { 191 this.fieldInfo = new SubmitField(subElement, this); 192 } else if ("reset".equals(subElementName)) { 193 this.fieldInfo = new ResetField(subElement, this); 194 } else if ("hidden".equals(subElementName)) { 195 this.fieldInfo = new HiddenField(subElement, this); 196 } else if ("ignored".equals(subElementName)) { 197 this.fieldInfo = new IgnoredField(subElement, this); 198 } else if ("text-find".equals(subElementName)) { 199 this.fieldInfo = new TextFindField(subElement, this); 200 } else if ("date-find".equals(subElementName)) { 201 this.fieldInfo = new DateFindField(subElement, this); 202 } else if ("range-find".equals(subElementName)) { 203 this.fieldInfo = new RangeFindField(subElement, this); 204 } else if ("lookup".equals(subElementName)) { 205 this.fieldInfo = new LookupField(subElement, this); 206 } else if ("file".equals(subElementName)) { 207 this.fieldInfo = new FileField(subElement, this); 208 } else if ("password".equals(subElementName)) { 209 this.fieldInfo = new PasswordField(subElement, this); 210 } else if ("image".equals(subElementName)) { 211 this.fieldInfo = new ImageField(subElement, this); 212 } else { 213 throw new IllegalArgumentException ("The field sub-element with name " + subElementName + " is not supported"); 214 } 215 } 216 } 217 218 public void mergeOverrideModelFormField(ModelFormField overrideFormField) { 219 if (overrideFormField == null) 220 return; 221 if (UtilValidate.isNotEmpty(overrideFormField.name)) 223 this.name = overrideFormField.name; 224 if (overrideFormField.mapAcsr != null && !overrideFormField.mapAcsr.isEmpty()) { 225 this.mapAcsr = overrideFormField.mapAcsr; 227 } 228 if (UtilValidate.isNotEmpty(overrideFormField.entityName)) 229 this.entityName = overrideFormField.entityName; 230 if (UtilValidate.isNotEmpty(overrideFormField.serviceName)) 231 this.serviceName = overrideFormField.serviceName; 232 if (overrideFormField.entryAcsr != null && !overrideFormField.entryAcsr.isEmpty()) 233 this.entryAcsr = overrideFormField.entryAcsr; 234 if (UtilValidate.isNotEmpty(overrideFormField.parameterName)) 235 this.parameterName = overrideFormField.parameterName; 236 if (UtilValidate.isNotEmpty(overrideFormField.fieldName)) 237 this.fieldName = overrideFormField.fieldName; 238 if (UtilValidate.isNotEmpty(overrideFormField.attributeName)) 239 this.attributeName = overrideFormField.attributeName; 240 if (overrideFormField.title != null && !overrideFormField.title.isEmpty()) 241 this.title = overrideFormField.title; 242 if (overrideFormField.tooltip != null && !overrideFormField.tooltip.isEmpty()) 243 this.tooltip = overrideFormField.tooltip; 244 245 if (UtilValidate.isNotEmpty(overrideFormField.titleAreaStyle)) 246 this.titleAreaStyle = overrideFormField.titleAreaStyle; 247 if (UtilValidate.isNotEmpty(overrideFormField.widgetAreaStyle)) 248 this.widgetAreaStyle = overrideFormField.widgetAreaStyle; 249 if (UtilValidate.isNotEmpty(overrideFormField.titleStyle)) 250 this.titleStyle = overrideFormField.titleStyle; 251 if (UtilValidate.isNotEmpty(overrideFormField.widgetStyle)) 252 this.widgetStyle = overrideFormField.widgetStyle; 253 if (overrideFormField.position != null) 254 this.position = overrideFormField.position; 255 if (UtilValidate.isNotEmpty(overrideFormField.redWhen)) 256 this.redWhen = overrideFormField.redWhen; 257 if (UtilValidate.isNotEmpty(overrideFormField.event)) 258 this.event = overrideFormField.event; 259 if (UtilValidate.isNotEmpty(overrideFormField.action)) 260 this.action = overrideFormField.action; 261 if (overrideFormField.useWhen != null && !overrideFormField.useWhen.isEmpty()) 262 this.useWhen = overrideFormField.useWhen; 263 if (overrideFormField.fieldInfo != null) { 264 this.setFieldInfo(overrideFormField.fieldInfo); 265 } 266 if (overrideFormField.fieldInfo != null) { 267 this.setHeaderLink(overrideFormField.headerLink); 268 } 269 if (UtilValidate.isNotEmpty(overrideFormField.idName)) 270 this.idName = overrideFormField.idName; 271 } 272 273 public boolean induceFieldInfo(String defaultFieldType) { 274 if (this.induceFieldInfoFromEntityField(defaultFieldType)) { 275 return true; 276 } 277 if (this.induceFieldInfoFromServiceParam(defaultFieldType)) { 278 return true; 279 } 280 return false; 281 } 282 283 public boolean induceFieldInfoFromServiceParam(String defaultFieldType) { 284 if (UtilValidate.isEmpty(this.getServiceName()) || UtilValidate.isEmpty(this.getAttributeName())) { 285 return false; 286 } 287 LocalDispatcher dispatcher = this.getModelForm().getDispacher(); 288 try { 289 ModelService modelService = dispatcher.getDispatchContext().getModelService(this.getServiceName()); 290 if (modelService != null) { 291 ModelParam modelParam = modelService.getParam(this.getAttributeName()); 292 if (modelParam != null) { 293 if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) { 294 this.entityName = modelParam.entityName; 295 this.fieldName = modelParam.fieldName; 296 if (this.induceFieldInfoFromEntityField(defaultFieldType)) { 297 return true; 298 } 299 } 300 301 this.induceFieldInfoFromServiceParam(modelService, modelParam, defaultFieldType); 302 return true; 303 } 304 } 305 } catch (GenericServiceException e) { 306 Debug.logError(e, "error getting service parameter definition for auto-field with serviceName: " + this.getServiceName() + ", and attributeName: " + this.getAttributeName(), module); 307 } 308 return false; 309 } 310 311 public boolean induceFieldInfoFromServiceParam(ModelService modelService, ModelParam modelParam, String defaultFieldType) { 312 if (modelService == null || modelParam == null) { 313 return false; 314 } 315 316 this.serviceName = modelService.name; 317 this.attributeName = modelParam.name; 318 319 if ("find".equals(defaultFieldType)) { 320 if (modelParam.type.indexOf("Double") != -1 321 || modelParam.type.indexOf("Float") != -1 322 || modelParam.type.indexOf("Long") != -1 323 || modelParam.type.indexOf("Integer") != -1) { 324 ModelFormField.RangeFindField textField = new ModelFormField.RangeFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 325 textField.setSize(6); 326 this.setFieldInfo(textField); 327 } else if (modelParam.type.indexOf("Timestamp") != -1) { 328 ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 329 dateTimeField.setType("timestamp"); 330 this.setFieldInfo(dateTimeField); 331 } else if (modelParam.type.indexOf("Date") != -1) { 332 ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 333 dateTimeField.setType("date"); 334 this.setFieldInfo(dateTimeField); 335 } else if (modelParam.type.indexOf("Time") != -1) { 336 ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 337 dateTimeField.setType("time"); 338 this.setFieldInfo(dateTimeField); 339 } else { 340 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 341 this.setFieldInfo(textField); 342 } 343 } else if ("display".equals(defaultFieldType)) { 344 ModelFormField.DisplayField displayField = new ModelFormField.DisplayField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 345 this.setFieldInfo(displayField); 346 } else { 347 if (modelParam.type.indexOf("Double") != -1 349 || modelParam.type.indexOf("Float") != -1 350 || modelParam.type.indexOf("Long") != -1 351 || modelParam.type.indexOf("Integer") != -1) { 352 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 353 textField.setSize(6); 354 this.setFieldInfo(textField); 355 } else if (modelParam.type.indexOf("Timestamp") != -1) { 356 ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 357 dateTimeField.setType("timestamp"); 358 this.setFieldInfo(dateTimeField); 359 } else if (modelParam.type.indexOf("Date") != -1) { 360 ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 361 dateTimeField.setType("date"); 362 this.setFieldInfo(dateTimeField); 363 } else if (modelParam.type.indexOf("Time") != -1) { 364 ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 365 dateTimeField.setType("time"); 366 this.setFieldInfo(dateTimeField); 367 } else { 368 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 369 this.setFieldInfo(textField); 370 } 371 } 372 373 return true; 374 } 375 376 public boolean induceFieldInfoFromEntityField(String defaultFieldType) { 377 if (UtilValidate.isEmpty(this.getEntityName()) || UtilValidate.isEmpty(this.getFieldName())) { 378 return false; 379 } 380 GenericDelegator delegator = this.getModelForm().getDelegator(); 381 ModelEntity modelEntity = delegator.getModelEntity(this.getEntityName()); 382 if (modelEntity != null) { 383 ModelField modelField = modelEntity.getField(this.getFieldName()); 384 if (modelField != null) { 385 this.induceFieldInfoFromEntityField(modelEntity, modelField, defaultFieldType); 387 return true; 388 } 389 } 390 return false; 391 } 392 393 public boolean induceFieldInfoFromEntityField(ModelEntity modelEntity, ModelField modelField, String defaultFieldType) { 394 if (modelEntity == null || modelField == null) { 395 return false; 396 } 397 398 this.entityName = modelEntity.getEntityName(); 399 this.fieldName = modelField.getName(); 400 401 if ("find".equals(defaultFieldType)) { 402 if ("id".equals(modelField.getType()) || "id-ne".equals(modelField.getType())) { 403 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 404 textField.setSize(20); 405 textField.setMaxlength(new Integer (20)); 406 this.setFieldInfo(textField); 407 } else if ("id-long".equals(modelField.getType()) || "id-long-ne".equals(modelField.getType())) { 408 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 409 textField.setSize(40); 410 textField.setMaxlength(new Integer (60)); 411 this.setFieldInfo(textField); 412 } else if ("id-vlong".equals(modelField.getType()) || "id-vlong-ne".equals(modelField.getType())) { 413 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 414 textField.setSize(60); 415 textField.setMaxlength(new Integer (250)); 416 this.setFieldInfo(textField); 417 } else if ("very-short".equals(modelField.getType())) { 418 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 419 textField.setSize(6); 420 textField.setMaxlength(new Integer (10)); 421 this.setFieldInfo(textField); 422 } else if ("name".equals(modelField.getType()) || "short-varchar".equals(modelField.getType())) { 423 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 424 textField.setSize(40); 425 textField.setMaxlength(new Integer (60)); 426 this.setFieldInfo(textField); 427 } else if ( 428 "value".equals(modelField.getType()) 429 || "comment".equals(modelField.getType()) 430 || "description".equals(modelField.getType()) 431 || "long-varchar".equals(modelField.getType()) 432 || "url".equals(modelField.getType()) 433 || "email".equals(modelField.getType())) { 434 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 435 textField.setSize(60); 436 textField.setMaxlength(new Integer (250)); 437 this.setFieldInfo(textField); 438 } else if ( 439 "floating-point".equals(modelField.getType()) || "currency-amount".equals(modelField.getType()) || "numeric".equals(modelField.getType())) { 440 ModelFormField.RangeFindField textField = new ModelFormField.RangeFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 441 textField.setSize(6); 442 this.setFieldInfo(textField); 443 } else if ("date-time".equals(modelField.getType()) || "date".equals(modelField.getType()) || "time".equals(modelField.getType())) { 444 ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 445 if ("date-time".equals(modelField.getType())) { 446 dateTimeField.setType("timestamp"); 447 } else if ("date".equals(modelField.getType())) { 448 dateTimeField.setType("date"); 449 } else if ("time".equals(modelField.getType())) { 450 dateTimeField.setType("time"); 451 } 452 this.setFieldInfo(dateTimeField); 453 } else { 454 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 455 this.setFieldInfo(textField); 456 } 457 } else if ("display".equals(defaultFieldType)) { 458 ModelFormField.DisplayField displayField = new ModelFormField.DisplayField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 459 this.setFieldInfo(displayField); 460 } else if ("hidden".equals(defaultFieldType)) { 461 ModelFormField.HiddenField hiddenField = new ModelFormField.HiddenField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this); 462 this.setFieldInfo(hiddenField); 463 } else { 464 if ("id".equals(modelField.getType()) || "id-ne".equals(modelField.getType())) { 465 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 466 textField.setSize(20); 467 textField.setMaxlength(new Integer (20)); 468 this.setFieldInfo(textField); 469 } else if ("id-long".equals(modelField.getType()) || "id-long-ne".equals(modelField.getType())) { 470 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 471 textField.setSize(40); 472 textField.setMaxlength(new Integer (60)); 473 this.setFieldInfo(textField); 474 } else if ("id-vlong".equals(modelField.getType()) || "id-vlong-ne".equals(modelField.getType())) { 475 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 476 textField.setSize(60); 477 textField.setMaxlength(new Integer (250)); 478 this.setFieldInfo(textField); 479 } else if ("indicator".equals(modelField.getType())) { 480 ModelFormField.DropDownField dropDownField = new ModelFormField.DropDownField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 481 dropDownField.setAllowEmpty(false); 482 dropDownField.addOptionSource(new ModelFormField.SingleOption("Y", null, dropDownField)); 483 dropDownField.addOptionSource(new ModelFormField.SingleOption("N", null, dropDownField)); 484 this.setFieldInfo(dropDownField); 485 } else if ("very-short".equals(modelField.getType())) { 490 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 491 textField.setSize(6); 492 textField.setMaxlength(new Integer (10)); 493 this.setFieldInfo(textField); 494 } else if ("very-long".equals(modelField.getType())) { 495 ModelFormField.TextareaField textareaField = new ModelFormField.TextareaField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 496 textareaField.setCols(60); 497 textareaField.setRows(2); 498 this.setFieldInfo(textareaField); 499 } else if ("name".equals(modelField.getType()) || "short-varchar".equals(modelField.getType())) { 500 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 501 textField.setSize(40); 502 textField.setMaxlength(new Integer (60)); 503 this.setFieldInfo(textField); 504 } else if ( 505 "value".equals(modelField.getType()) 506 || "comment".equals(modelField.getType()) 507 || "description".equals(modelField.getType()) 508 || "long-varchar".equals(modelField.getType()) 509 || "url".equals(modelField.getType()) 510 || "email".equals(modelField.getType())) { 511 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 512 textField.setSize(60); 513 textField.setMaxlength(new Integer (250)); 514 this.setFieldInfo(textField); 515 } else if ( 516 "floating-point".equals(modelField.getType()) || "currency-amount".equals(modelField.getType()) || "numeric".equals(modelField.getType())) { 517 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 518 textField.setSize(6); 519 this.setFieldInfo(textField); 520 } else if ("date-time".equals(modelField.getType()) || "date".equals(modelField.getType()) || "time".equals(modelField.getType())) { 521 ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 522 if ("date-time".equals(modelField.getType())) { 523 dateTimeField.setType("timestamp"); 524 } else if ("date".equals(modelField.getType())) { 525 dateTimeField.setType("date"); 526 } else if ("time".equals(modelField.getType())) { 527 dateTimeField.setType("time"); 528 } 529 this.setFieldInfo(dateTimeField); 530 } else { 531 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this); 532 this.setFieldInfo(textField); 533 } 534 } 535 536 return true; 537 } 538 539 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 540 this.fieldInfo.renderFieldString(buffer, context, formStringRenderer); 541 } 542 543 546 public FieldInfo getFieldInfo() { 547 return fieldInfo; 548 } 549 550 553 public ModelForm getModelForm() { 554 return modelForm; 555 } 556 557 560 public void setFieldInfo(FieldInfo fieldInfo) { 561 if (fieldInfo == null) 562 return; 563 564 if (this.fieldInfo == null || (fieldInfo.getFieldSource() <= this.fieldInfo.getFieldSource())) { 566 this.fieldInfo = fieldInfo; 567 this.fieldInfo.modelFormField = this; 568 } 569 } 570 571 578 public String getAttributeName() { 579 if (UtilValidate.isNotEmpty(this.attributeName)) { 580 return this.attributeName; 581 } else { 582 return this.name; 583 } 584 } 585 586 589 public String getEntityName() { 590 if (UtilValidate.isNotEmpty(this.entityName)) { 591 return this.entityName; 592 } else { 593 return this.modelForm.getDefaultEntityName(); 594 } 595 } 596 597 600 public String getEntryName() { 601 if (this.entryAcsr != null && !this.entryAcsr.isEmpty()) { 602 return this.entryAcsr.getOriginalName(); 603 } else { 604 return this.name; 605 } 606 } 607 608 617 public String getEntry(Map context) { 618 return this.getEntry(context, ""); 619 } 620 621 public String getEntry(Map context, String defaultValue) { 622 Boolean isError = (Boolean ) context.get("isError"); 623 Boolean useRequestParameters = (Boolean ) context.get("useRequestParameters"); 624 625 Locale locale = (Locale ) context.get("locale"); 626 if (locale == null) locale = Locale.getDefault(); 627 628 if ((Boolean.TRUE.equals(isError) && !Boolean.FALSE.equals(useRequestParameters)) || (Boolean.TRUE.equals(useRequestParameters))) { 631 Map parameters = (Map ) context.get("parameters"); 633 if (parameters != null && parameters.get(this.getParameterName(context)) != null) { 634 return (String ) parameters.get(this.getParameterName(context)); 635 } else { 636 return defaultValue; 637 } 638 } else { 639 Map dataMap = this.getMap(context); 641 boolean dataMapIsContext = false; 642 if (dataMap == null) { 643 dataMap = context; 645 dataMapIsContext = true; 646 } 647 Object retVal = null; 648 if (this.entryAcsr != null && !this.entryAcsr.isEmpty()) { 649 retVal = this.entryAcsr.get(dataMap); 651 } else { 652 retVal = dataMap.get(this.name); 655 } 656 657 if (dataMapIsContext && retVal == null && !Boolean.FALSE.equals(useRequestParameters)) { 659 Map parameters = (Map ) context.get("parameters"); 660 if (parameters != null) { 661 if (this.entryAcsr != null && !this.entryAcsr.isEmpty()) { 662 retVal = this.entryAcsr.get(parameters); 663 } else { 664 retVal = parameters.get(this.name); 665 } 666 } 667 } 668 669 if (retVal != null) { 670 if (retVal instanceof Double || retVal instanceof Float || retVal instanceof BigDecimal ) { 672 NumberFormat nf = NumberFormat.getInstance(locale); 673 nf.setMaximumFractionDigits(10); 674 return nf.format(retVal); 675 } else { 676 return retVal.toString(); 677 } 678 } else { 679 return defaultValue; 680 } 681 } 682 } 683 684 public Map getMap(Map context) { 685 if (this.mapAcsr == null || this.mapAcsr.isEmpty()) { 686 return this.modelForm.getDefaultMap(context); 688 } else { 689 return (Map ) mapAcsr.get(context); 691 } 692 } 693 694 701 public String getFieldName() { 702 if (UtilValidate.isNotEmpty(this.fieldName)) { 703 return this.fieldName; 704 } else { 705 return this.name; 706 } 707 } 708 709 717 public String getMapName() { 718 if (this.mapAcsr != null && !this.mapAcsr.isEmpty()) { 719 return this.mapAcsr.getOriginalName(); 720 } else { 721 return this.modelForm.getDefaultMapName(); 722 } 723 } 724 725 728 public String getName() { 729 return name; 730 } 731 732 738 public String getParameterName(Map context) { 739 String baseName; 740 if (UtilValidate.isNotEmpty(this.parameterName)) { 741 baseName = this.parameterName; 742 } else { 743 baseName = this.name; 744 } 745 746 Integer itemIndex = (Integer ) context.get("itemIndex"); 747 if (itemIndex != null && "multi".equals(this.modelForm.getType())) { 748 return baseName + this.modelForm.getItemIndexSeparator() + itemIndex.intValue(); 749 } else { 750 return baseName; 751 } 752 } 753 754 757 public int getPosition() { 758 if (this.position == null) { 759 return 1; 760 } else { 761 return position.intValue(); 762 } 763 } 764 765 768 public String getRedWhen() { 769 return redWhen; 770 } 771 772 773 776 public String getEvent() { 777 return event; 778 } 779 780 783 public String getAction() { 784 return action; 785 } 786 787 796 public boolean shouldBeRed(Map context) { 797 799 String redCondition = this.redWhen; 800 801 if ("never".equals(redCondition)) { 802 return false; 803 } 804 805 if (UtilValidate.isEmpty(redCondition) || "by-name".equals(redCondition)) { 807 if ("fromDate".equals(this.name) || (this.entryAcsr != null && "fromDate".equals(this.entryAcsr.getOriginalName()))) { 808 redCondition = "after-now"; 809 } else if ("thruDate".equals(this.name) || (this.entryAcsr != null && "thruDate".equals(this.entryAcsr.getOriginalName()))) { 810 redCondition = "before-now"; 811 } else { 812 return false; 813 } 814 } 815 816 boolean isBeforeNow = false; 817 if ("before-now".equals(redCondition)) { 818 isBeforeNow = true; 819 } else if ("after-now".equals(redCondition)) { 820 isBeforeNow = false; 821 } else { 822 return false; 823 } 824 825 java.sql.Date dateVal = null; 826 java.sql.Time timeVal = null; 827 java.sql.Timestamp timestampVal = null; 828 829 String value = this.getEntry(context); 831 try { 832 timestampVal = java.sql.Timestamp.valueOf(value); 833 } catch (Exception e) { 834 } 836 837 if (timestampVal == null) { 838 try { 839 dateVal = java.sql.Date.valueOf(value); 840 } catch (Exception e) { 841 } 843 } 844 845 if (timestampVal == null && dateVal == null) { 846 try { 847 timeVal = java.sql.Time.valueOf(value); 848 } catch (Exception e) { 849 } 851 } 852 853 if (timestampVal == null && dateVal == null && timeVal == null) { 854 return false; 855 } 856 857 long nowMillis = System.currentTimeMillis(); 858 if (timestampVal != null) { 859 java.sql.Timestamp nowStamp = new java.sql.Timestamp (nowMillis); 860 if (!timestampVal.equals(nowStamp)) { 861 if (isBeforeNow) { 862 if (timestampVal.before(nowStamp)) { 863 return true; 864 } 865 } else { 866 if (timestampVal.after(nowStamp)) { 867 return true; 868 } 869 } 870 } 871 } else if (dateVal != null) { 872 java.sql.Date nowDate = new java.sql.Date (nowMillis); 873 if (!dateVal.equals(nowDate)) { 874 if (isBeforeNow) { 875 if (dateVal.before(nowDate)) { 876 return true; 877 } 878 } else { 879 if (dateVal.after(nowDate)) { 880 return true; 881 } 882 } 883 } 884 } else if (timeVal != null) { 885 java.sql.Time nowTime = new java.sql.Time (nowMillis); 886 if (!timeVal.equals(nowTime)) { 887 if (isBeforeNow) { 888 if (timeVal.before(nowTime)) { 889 return true; 890 } 891 } else { 892 if (timeVal.after(nowTime)) { 893 return true; 894 } 895 } 896 } 897 } 898 899 return false; 900 } 901 902 905 public String getServiceName() { 906 if (UtilValidate.isNotEmpty(this.serviceName)) { 907 return this.serviceName; 908 } else { 909 return this.modelForm.getDefaultServiceName(); 910 } 911 } 912 913 916 public String getTitle(Map context) { 917 if (this.title != null && this.title.getOriginal() != null) { 918 return title.expandString(context); 919 } else { 920 if (this.name == null || this.name.length() == 0) { 922 return ""; 924 } 925 926 Map uiLabelMap = (Map ) context.get("uiLabelMap"); 928 if (uiLabelMap != null) { 929 String titleFieldName = "FormFieldTitle_" + this.name; 930 String localizedName = (String ) uiLabelMap.get(titleFieldName); 931 if (!localizedName.equals(titleFieldName)) { 932 return localizedName; 933 } 934 } else { 935 Debug.logWarning("Could not find uiLabelMap in context while rendering form " + this.modelForm.getName(), module); 936 } 937 938 StringBuffer autoTitleBuffer = new StringBuffer (); 940 941 autoTitleBuffer.append(Character.toUpperCase(this.name.charAt(0))); 943 944 for (int i = 1; i < this.name.length(); i++) { 946 char curChar = this.name.charAt(i); 947 if (Character.isUpperCase(curChar)) { 948 autoTitleBuffer.append(' '); 949 } 950 autoTitleBuffer.append(curChar); 951 } 952 953 return autoTitleBuffer.toString(); 954 } 955 } 956 957 960 public String getTitleAreaStyle() { 961 if (UtilValidate.isNotEmpty(this.titleAreaStyle)) { 962 return this.titleAreaStyle; 963 } else { 964 return this.modelForm.getDefaultTitleAreaStyle(); 965 } 966 } 967 968 971 public String getTitleStyle() { 972 if (UtilValidate.isNotEmpty(this.titleStyle)) { 973 return this.titleStyle; 974 } else { 975 return this.modelForm.getDefaultTitleStyle(); 976 } 977 } 978 979 982 public String getRequiredFieldStyle() { 983 if (UtilValidate.isNotEmpty(this.requiredFieldStyle)) { 984 return this.requiredFieldStyle; 985 } else { 986 return this.modelForm.getDefaultRequiredFieldStyle(); 987 } 988 } 989 990 993 public String getTooltip(Map context) { 994 if (tooltip != null && !tooltip.isEmpty()) { 995 return tooltip.expandString(context); 996 } else { 997 return ""; 998 } 999 } 1000 1001 1004 public String getUseWhen(Map context) { 1005 if (useWhen != null && !useWhen.isEmpty()) { 1006 return useWhen.expandString(context); 1007 } else { 1008 return ""; 1009 } 1010 } 1011 1012 1015 public String getIdName() { 1016 return idName; 1017 } 1018 1019 1022 public String getHeaderLink() { 1023 return headerLink; 1024 } 1025 1026 public String getHeaderLinkStyle() { 1027 return headerLinkStyle; 1028 } 1029 1030 1031 1034 public void setIdName(String string) { 1035 idName = string; 1036 } 1037 1038 1039 public boolean isUseWhenEmpty() { 1040 if (this.useWhen == null) { 1041 return true; 1042 } 1043 1044 return this.useWhen.isEmpty(); 1045 } 1046 1047 public boolean shouldUse(Map context) { 1048 String useWhenStr = this.getUseWhen(context); 1049 if (UtilValidate.isEmpty(useWhenStr)) { 1050 return true; 1051 } else { 1052 try { 1053 Interpreter bsh = this.modelForm.getBshInterpreter(context); 1054 Object retVal = bsh.eval(useWhenStr); 1055 boolean condTrue = false; 1056 if (retVal instanceof Boolean ) { 1058 Boolean boolVal = (Boolean ) retVal; 1059 condTrue = boolVal.booleanValue(); 1060 } else { 1061 throw new IllegalArgumentException ("Return value from use-when condition eval was not a Boolean: " 1062 + retVal.getClass().getName() + " [" + retVal + "] on the field " + this.name + " of form " + this.modelForm.name); 1063 } 1064 1065 return condTrue; 1066 } catch (EvalError e) { 1067 String errMsg = "Error evaluating BeanShell use-when condition [" + useWhenStr + "] on the field " 1068 + this.name + " of form " + this.modelForm.name + ": " + e.toString(); 1069 Debug.logError(e, errMsg, module); 1070 throw new IllegalArgumentException (errMsg); 1072 } 1073 } 1074 } 1075 1076 1079 public boolean isRowSubmit() { 1080 if (!"multi".equals(getModelForm().getType())) return false; 1081 if (getFieldInfo().getFieldType() != ModelFormField.FieldInfo.CHECK) return false; 1082 if (!CheckField.ROW_SUBMIT_FIELD_NAME.equals(getName())) return false; 1083 return true; 1084 } 1085 1086 1089 public String getWidgetAreaStyle() { 1090 if (UtilValidate.isNotEmpty(this.widgetAreaStyle)) { 1091 return this.widgetAreaStyle; 1092 } else { 1093 return this.modelForm.getDefaultWidgetAreaStyle(); 1094 } 1095 } 1096 1097 1100 public String getWidgetStyle() { 1101 if (UtilValidate.isNotEmpty(this.widgetStyle)) { 1102 return this.widgetStyle; 1103 } else { 1104 return this.modelForm.getDefaultWidgetStyle(); 1105 } 1106 } 1107 1108 1111 public String getTooltipStyle() { 1112 if (UtilValidate.isNotEmpty(this.tooltipStyle)) { 1113 return this.tooltipStyle; 1114 } else { 1115 return this.modelForm.getDefaultTooltipStyle(); 1116 } 1117 } 1118 1119 1122 public void setAttributeName(String string) { 1123 attributeName = string; 1124 } 1125 1126 1129 public void setEntityName(String string) { 1130 entityName = string; 1131 } 1132 1133 1136 public void setEntryName(String string) { 1137 entryAcsr = new FlexibleMapAccessor(string); 1138 } 1139 1140 1143 public void setFieldName(String string) { 1144 fieldName = string; 1145 } 1146 1147 1150 public void setMapName(String string) { 1151 this.mapAcsr = new FlexibleMapAccessor(string); 1152 } 1153 1154 1157 public void setName(String string) { 1158 name = string; 1159 } 1160 1161 1164 public void setParameterName(String string) { 1165 parameterName = string; 1166 } 1167 1168 1171 public void setPosition(int i) { 1172 position = new Integer (i); 1173 } 1174 1175 1178 public void setRedWhen(String string) { 1179 redWhen = string; 1180 } 1181 1182 1183 1186 public void setEvent(String string) { 1187 event = string; 1188 } 1189 1190 1193 public void setAction(String string) { 1194 action = string; 1195 } 1196 1197 1200 public void setServiceName(String string) { 1201 serviceName = string; 1202 } 1203 1204 1207 public void setTitle(String string) { 1208 this.title = new FlexibleStringExpander(string); 1209 } 1210 1211 1214 public void setTitleAreaStyle(String string) { 1215 this.titleAreaStyle = string; 1216 } 1217 1218 1221 public void setTitleStyle(String string) { 1222 this.titleStyle = string; 1223 } 1224 1225 1228 public void setTooltip(String string) { 1229 this.tooltip = new FlexibleStringExpander(string); 1230 } 1231 1232 1235 public void setUseWhen(String string) { 1236 this.useWhen = new FlexibleStringExpander(string); 1237 } 1238 1239 1242 public void setWidgetAreaStyle(String string) { 1243 this.widgetAreaStyle = string; 1244 } 1245 1246 1249 public void setWidgetStyle(String string) { 1250 this.widgetStyle = string; 1251 } 1252 1253 1256 public void setTooltipStyle(String string) { 1257 this.tooltipStyle = string; 1258 } 1259 1260 1263 public boolean getSeparateColumn() { 1264 return this.separateColumn; 1265 } 1266 1267 1270 public void setHeaderLink(String string) { 1271 this.headerLink = string; 1272 } 1273 1274 1277 public void setHeaderLinkStyle(String string) { 1278 this.headerLinkStyle = string; 1279 } 1280 1281 1282 1285 public boolean getRequiredField() { 1286 return this.requiredField; 1287 } 1288 1289 1292 public void setModelForm(ModelForm modelForm) { 1293 this.modelForm = modelForm; 1294 } 1295 1296 1297 public static abstract class FieldInfo { 1298 1299 public static final int DISPLAY = 1; 1300 public static final int HYPERLINK = 2; 1301 public static final int TEXT = 3; 1302 public static final int TEXTAREA = 4; 1303 public static final int DATE_TIME = 5; 1304 public static final int DROP_DOWN = 6; 1305 public static final int CHECK = 7; 1306 public static final int RADIO = 8; 1307 public static final int SUBMIT = 9; 1308 public static final int RESET = 10; 1309 public static final int HIDDEN = 11; 1310 public static final int IGNORED = 12; 1311 public static final int TEXTQBE = 13; 1312 public static final int DATEQBE = 14; 1313 public static final int RANGEQBE = 15; 1314 public static final int LOOKUP = 16; 1315 public static final int FILE = 17; 1316 public static final int PASSWORD = 18; 1317 public static final int IMAGE = 19; 1318 public static final int DISPLAY_ENTITY = 20; 1319 1320 public static final int SOURCE_EXPLICIT = 1; 1325 public static final int SOURCE_AUTO_ENTITY = 2; 1326 public static final int SOURCE_AUTO_SERVICE = 3; 1327 1328 public static Map fieldTypeByName = new HashMap (); 1329 1330 static { 1331 fieldTypeByName.put("display", new Integer (1)); 1332 fieldTypeByName.put("hyperlink", new Integer (2)); 1333 fieldTypeByName.put("text", new Integer (3)); 1334 fieldTypeByName.put("textarea", new Integer (4)); 1335 fieldTypeByName.put("date-time", new Integer (5)); 1336 fieldTypeByName.put("drop-down", new Integer (6)); 1337 fieldTypeByName.put("check", new Integer (7)); 1338 fieldTypeByName.put("radio", new Integer (8)); 1339 fieldTypeByName.put("submit", new Integer (9)); 1340 fieldTypeByName.put("reset", new Integer (10)); 1341 fieldTypeByName.put("hidden", new Integer (11)); 1342 fieldTypeByName.put("ignored", new Integer (12)); 1343 fieldTypeByName.put("text-find", new Integer (13)); 1344 fieldTypeByName.put("date-find", new Integer (14)); 1345 fieldTypeByName.put("range-find", new Integer (15)); 1346 fieldTypeByName.put("lookup", new Integer (16)); 1347 fieldTypeByName.put("file", new Integer (17)); 1348 fieldTypeByName.put("password", new Integer (18)); 1349 fieldTypeByName.put("image", new Integer (19)); 1350 fieldTypeByName.put("display-entity", new Integer (20)); 1351 } 1352 1353 protected int fieldType; 1354 protected int fieldSource; 1355 protected ModelFormField modelFormField; 1356 1357 1358 protected FieldInfo() {} 1359 1360 1361 public FieldInfo(int fieldSource, int fieldType, ModelFormField modelFormField) { 1362 this.fieldType = fieldType; 1363 this.fieldSource = fieldSource; 1364 this.modelFormField = modelFormField; 1365 } 1366 1367 1368 public FieldInfo(Element element, ModelFormField modelFormField) { 1369 this.fieldSource = FieldInfo.SOURCE_EXPLICIT; 1370 this.fieldType = findFieldTypeFromName(element.getTagName()); 1371 this.modelFormField = modelFormField; 1372 } 1373 1374 1377 public ModelFormField getModelFormField() { 1378 return modelFormField; 1379 } 1380 1381 1384 public int getFieldType() { 1385 return fieldType; 1386 } 1387 1388 1391 public int getFieldSource() { 1392 return this.fieldSource; 1393 } 1394 1395 public static int findFieldTypeFromName(String name) { 1396 Integer fieldTypeInt = (Integer ) FieldInfo.fieldTypeByName.get(name); 1397 if (fieldTypeInt != null) { 1398 return fieldTypeInt.intValue(); 1399 } else { 1400 throw new IllegalArgumentException ("Could not get fieldType for field type name " + name); 1401 } 1402 } 1403 1404 public abstract void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer); 1405 } 1406 1407 public static abstract class FieldInfoWithOptions extends FieldInfo { 1408 protected FieldInfoWithOptions() { 1409 super(); 1410 } 1411 1412 protected FlexibleStringExpander noCurrentSelectedKey = null; 1413 protected List optionSources = new LinkedList (); 1414 1415 public FieldInfoWithOptions(int fieldSource, int fieldType, ModelFormField modelFormField) { 1416 super(fieldSource, fieldType, modelFormField); 1417 } 1418 1419 public FieldInfoWithOptions(Element element, ModelFormField modelFormField) { 1420 super(element, modelFormField); 1421 1422 noCurrentSelectedKey = new FlexibleStringExpander(element.getAttribute("no-current-selected-key")); 1423 1424 List childElements = UtilXml.childElementList(element); 1426 Iterator childElementIter = childElements.iterator(); 1427 while (childElementIter.hasNext()) { 1428 Element childElement = (Element ) childElementIter.next(); 1429 if ("option".equals(childElement.getTagName())) { 1430 this.addOptionSource(new SingleOption(childElement, this)); 1431 } else if ("list-options".equals(childElement.getTagName())) { 1432 this.addOptionSource(new ListOptions(childElement, this)); 1433 } else if ("entity-options".equals(childElement.getTagName())) { 1434 this.addOptionSource(new EntityOptions(childElement, this)); 1435 } 1436 } 1437 } 1438 1439 public List getAllOptionValues(Map context, GenericDelegator delegator) { 1440 List optionValues = new LinkedList (); 1441 Iterator optionSourceIter = this.optionSources.iterator(); 1442 while (optionSourceIter.hasNext()) { 1443 OptionSource optionSource = (OptionSource) optionSourceIter.next(); 1444 optionSource.addOptionValues(optionValues, context, delegator); 1445 } 1446 return optionValues; 1447 } 1448 1449 public static String getDescriptionForOptionKey(String key, List allOptionValues) { 1450 if (UtilValidate.isEmpty(key)) { 1451 return ""; 1452 } 1453 1454 if (UtilValidate.isEmpty(allOptionValues)) { 1455 return key; 1456 } 1457 1458 Iterator optionValueIter = allOptionValues.iterator(); 1459 while (optionValueIter.hasNext()) { 1460 OptionValue optionValue = (OptionValue) optionValueIter.next(); 1461 if (key.equals(optionValue.getKey())) { 1462 return optionValue.getDescription(); 1463 } 1464 } 1465 1466 return key; 1468 } 1469 1470 public String getNoCurrentSelectedKey(Map context) { 1471 if (this.noCurrentSelectedKey == null) { 1472 return null; 1473 } 1474 return this.noCurrentSelectedKey.expandString(context); 1475 } 1476 1477 public void setNoCurrentSelectedKey(String string) { 1478 this.noCurrentSelectedKey = new FlexibleStringExpander(string); 1479 } 1480 1481 public void addOptionSource(OptionSource optionSource) { 1482 this.optionSources.add(optionSource); 1483 } 1484 } 1485 1486 public static class OptionValue { 1487 protected String key; 1488 protected String description; 1489 1490 public OptionValue(String key, String description) { 1491 this.key = key; 1492 this.description = description; 1493 } 1494 1495 public String getKey() { 1496 return key; 1497 } 1498 1499 public String getDescription() { 1500 return description; 1501 } 1502 } 1503 1504 public static abstract class OptionSource { 1505 protected FieldInfo fieldInfo; 1506 1507 public abstract void addOptionValues(List optionValues, Map context, GenericDelegator delegator); 1508 } 1509 1510 public static class SingleOption extends OptionSource { 1511 protected FlexibleStringExpander key; 1512 protected FlexibleStringExpander description; 1513 1514 public SingleOption(String key, String description, FieldInfo fieldInfo) { 1515 this.key = new FlexibleStringExpander(key); 1516 this.description = new FlexibleStringExpander(UtilXml.checkEmpty(description, key)); 1517 this.fieldInfo = fieldInfo; 1518 } 1519 1520 public SingleOption(Element optionElement, FieldInfo fieldInfo) { 1521 this.key = new FlexibleStringExpander(optionElement.getAttribute("key")); 1522 this.description = new FlexibleStringExpander(UtilXml.checkEmpty(optionElement.getAttribute("description"), optionElement.getAttribute("key"))); 1523 this.fieldInfo = fieldInfo; 1524 } 1525 1526 public void addOptionValues(List optionValues, Map context, GenericDelegator delegator) { 1527 optionValues.add(new OptionValue(key.expandString(context), description.expandString(context))); 1528 } 1529 } 1530 1531 public static class ListOptions extends OptionSource { 1532 protected FlexibleMapAccessor listAcsr; 1533 protected String listEntryName; 1534 protected FlexibleMapAccessor keyAcsr; 1535 protected FlexibleStringExpander description; 1536 1537 public ListOptions(String listName, String listEntryName, String keyName, String description, FieldInfo fieldInfo) { 1538 this.listAcsr = new FlexibleMapAccessor(listName); 1539 this.listEntryName = listEntryName; 1540 this.keyAcsr = new FlexibleMapAccessor(keyName); 1541 this.description = new FlexibleStringExpander(description); 1542 this.fieldInfo = fieldInfo; 1543 } 1544 1545 public ListOptions(Element optionElement, FieldInfo fieldInfo) { 1546 this.listEntryName = optionElement.getAttribute("list-entry-name"); 1547 this.listAcsr = new FlexibleMapAccessor(optionElement.getAttribute("list-name")); 1548 this.keyAcsr = new FlexibleMapAccessor(optionElement.getAttribute("key-name")); 1549 this.listAcsr = new FlexibleMapAccessor(optionElement.getAttribute("list-name")); 1550 this.listEntryName = optionElement.getAttribute("list-entry-name"); 1551 this.description = new FlexibleStringExpander(optionElement.getAttribute("description")); 1552 this.fieldInfo = fieldInfo; 1553 } 1554 1555 public void addOptionValues(List optionValues, Map context, GenericDelegator delegator) { 1556 List dataList = (List ) this.listAcsr.get(context); 1557 if (dataList != null && dataList.size() != 0) { 1558 Iterator dataIter = dataList.iterator(); 1559 while (dataIter.hasNext()) { 1560 Object data = dataIter.next(); 1561 Map localContext = new HashMap (context); 1562 if (UtilValidate.isNotEmpty(this.listEntryName)) { 1563 localContext.put(this.listEntryName, data); 1564 } else { 1565 localContext.putAll((Map ) data); 1566 } 1567 optionValues.add(new OptionValue((String ) keyAcsr.get(localContext), description.expandString(localContext))); 1568 } 1569 } 1570 } 1571 } 1572 1573 public static class EntityOptions extends OptionSource { 1574 protected String entityName; 1575 protected String keyFieldName; 1576 protected FlexibleStringExpander description; 1577 protected boolean cache = true; 1578 protected String filterByDate; 1579 1580 protected List constraintList = null; 1581 protected List orderByList = null; 1582 1583 public EntityOptions(FieldInfo fieldInfo) { 1584 this.fieldInfo = fieldInfo; 1585 } 1586 1587 public EntityOptions(Element entityOptionsElement, FieldInfo fieldInfo) { 1588 this.entityName = entityOptionsElement.getAttribute("entity-name"); 1589 this.keyFieldName = entityOptionsElement.getAttribute("key-field-name"); 1590 this.description = new FlexibleStringExpander(entityOptionsElement.getAttribute("description")); 1591 this.cache = !"false".equals(entityOptionsElement.getAttribute("cache")); 1592 this.filterByDate = entityOptionsElement.getAttribute("filter-by-date"); 1593 1594 List constraintElements = UtilXml.childElementList(entityOptionsElement, "entity-constraint"); 1595 if (constraintElements != null && constraintElements.size() > 0) { 1596 this.constraintList = new LinkedList (); 1597 Iterator constraintElementIter = constraintElements.iterator(); 1598 while (constraintElementIter.hasNext()) { 1599 Element constraintElement = (Element ) constraintElementIter.next(); 1600 constraintList.add(new EntityFinderUtil.ConditionExpr(constraintElement)); 1601 } 1602 } 1603 1604 List orderByElements = UtilXml.childElementList(entityOptionsElement, "entity-order-by"); 1605 if (orderByElements != null && orderByElements.size() > 0) { 1606 this.orderByList = new LinkedList (); 1607 Iterator orderByElementIter = orderByElements.iterator(); 1608 while (orderByElementIter.hasNext()) { 1609 Element orderByElement = (Element ) orderByElementIter.next(); 1610 orderByList.add(orderByElement.getAttribute("field-name")); 1611 } 1612 } 1613 1614 this.fieldInfo = fieldInfo; 1615 } 1616 1617 public String getKeyFieldName() { 1618 if (UtilValidate.isNotEmpty(this.keyFieldName)) { 1619 return this.keyFieldName; 1620 } else { 1621 return this.fieldInfo.getModelFormField().getFieldName(); 1623 } 1624 } 1625 1626 public void addOptionValues(List optionValues, Map context, GenericDelegator delegator) { 1627 EntityCondition findCondition = null; 1629 if (this.constraintList != null && this.constraintList.size() > 0) { 1630 List expandedConditionList = new LinkedList (); 1631 Iterator constraintIter = constraintList.iterator(); 1632 while (constraintIter.hasNext()) { 1633 EntityFinderUtil.Condition condition = (EntityFinderUtil.Condition) constraintIter.next(); 1634 expandedConditionList.add(condition.createCondition(context, this.entityName, delegator)); 1635 } 1636 findCondition = new EntityConditionList(expandedConditionList, EntityOperator.AND); 1637 } 1638 1639 try { 1640 List values = null; 1641 if (this.cache) { 1642 values = delegator.findByConditionCache(this.entityName, findCondition, null, this.orderByList); 1643 } else { 1644 values = delegator.findByCondition(this.entityName, findCondition, null, this.orderByList); 1645 } 1646 1647 if ("true".equals(this.filterByDate)) { 1649 values = EntityUtil.filterByDate(values, true); 1650 } else if (!"false".equals(this.filterByDate)) { 1651 ModelEntity modelEntity = delegator.getModelEntity(this.entityName); 1653 if (modelEntity != null && modelEntity.isField("fromDate") && modelEntity.isField("thruDate")) { 1654 values = EntityUtil.filterByDate(values, true); 1655 } 1656 } 1657 1658 Iterator valueIter = values.iterator(); 1659 while (valueIter.hasNext()) { 1660 GenericValue value = (GenericValue) valueIter.next(); 1661 MapStack localContext = null; 1664 if (context instanceof MapStack) { 1665 localContext = ((MapStack) context).standAloneStack(); 1666 localContext.push(value); 1667 } else { 1668 localContext = MapStack.create(context); 1669 localContext.push(value); 1670 } 1671 String optionDesc = this.description.expandString(localContext, UtilMisc.ensureLocale(context.get("locale"))); 1672 Object keyFieldObject = value.get(this.getKeyFieldName()); 1673 if (keyFieldObject == null) { 1674 throw new IllegalArgumentException ("The value found for key-name [" + this.getKeyFieldName() + "], may not be a valid key field name."); 1675 } 1676 String keyFieldValue = keyFieldObject.toString(); 1677 optionValues.add(new OptionValue(keyFieldValue, optionDesc)); 1678 } 1679 } catch (GenericEntityException e) { 1680 Debug.logError(e, "Error getting entity options in form", module); 1681 } 1682 } 1683 } 1684 1685 public static class DisplayField extends FieldInfo { 1686 protected boolean alsoHidden = true; 1687 protected FlexibleStringExpander description; 1688 protected String type; protected FlexibleStringExpander currency; 1690 1691 protected DisplayField() { 1692 super(); 1693 } 1694 1695 public DisplayField(ModelFormField modelFormField) { 1696 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DISPLAY, modelFormField); 1697 } 1698 1699 public DisplayField(int fieldSource, ModelFormField modelFormField) { 1700 super(fieldSource, FieldInfo.DISPLAY, modelFormField); 1701 } 1702 1703 public DisplayField(Element element, ModelFormField modelFormField) { 1704 super(element, modelFormField); 1705 this.type = element.getAttribute("type"); 1706 this.setCurrency(element.getAttribute("currency")); 1707 this.setDescription(element.getAttribute("description")); 1708 this.alsoHidden = !"false".equals(element.getAttribute("also-hidden")); 1709 } 1710 1711 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 1712 formStringRenderer.renderDisplayField(buffer, context, this); 1713 } 1714 1715 1718 public boolean getAlsoHidden() { 1719 return alsoHidden; 1720 } 1721 1722 1725 public String getDescription(Map context) { 1726 String retVal = null; 1727 if (this.description != null && !this.description.isEmpty()) { 1728 retVal = this.description.expandString(context); 1729 } else { 1730 retVal = modelFormField.getEntry(context); 1731 } 1732 if (retVal == null || retVal.length() == 0) { 1733 retVal = " "; 1734 } else if ("currency".equals(type)) { 1735 Locale locale = (Locale ) context.get("locale"); 1736 if (locale == null) locale = Locale.getDefault(); 1737 String isoCode = null; 1738 if (this.currency != null && !this.currency.isEmpty()) { 1739 isoCode = this.currency.expandString(context); 1740 } 1741 try { 1742 Double parsedRetVal = (Double ) ObjectType.simpleTypeConvert(retVal, "Double", null, locale, false); 1743 retVal = UtilFormatOut.formatCurrency(parsedRetVal, isoCode, locale); 1744 } catch (GeneralException e) { 1745 String errMsg = "Error formatting currency value [" + retVal + "]: " + e.toString(); 1746 Debug.logError(e, errMsg, module); 1747 throw new IllegalArgumentException (errMsg); 1748 } 1749 } 1750 return retVal; 1751 } 1752 1753 1756 public void setAlsoHidden(boolean b) { 1757 alsoHidden = b; 1758 } 1759 1760 1763 public void setDescription(String string) { 1764 description = new FlexibleStringExpander(string); 1765 } 1766 1767 1770 public void setCurrency(String string) { 1771 currency = new FlexibleStringExpander(string); 1772 } 1773 } 1774 1775 public static class DisplayEntityField extends DisplayField { 1776 protected String entityName; 1777 protected String keyFieldName; 1778 protected boolean cache = true; 1779 protected SubHyperlink subHyperlink; 1780 1781 protected DisplayEntityField() { 1782 super(); 1783 } 1784 1785 public DisplayEntityField(ModelFormField modelFormField) { 1786 super(modelFormField); 1787 this.fieldType = FieldInfo.DISPLAY_ENTITY; 1788 } 1789 1790 public DisplayEntityField(int fieldSource, ModelFormField modelFormField) { 1791 super(fieldSource, modelFormField); 1792 this.fieldType = FieldInfo.DISPLAY_ENTITY; 1793 } 1794 1795 public DisplayEntityField(Element element, ModelFormField modelFormField) { 1796 super(element, modelFormField); 1797 1798 this.entityName = element.getAttribute("entity-name"); 1799 this.keyFieldName = element.getAttribute("key-field-name"); 1800 this.cache = !"false".equals(element.getAttribute("cache")); 1801 1802 if (this.description == null || this.description.isEmpty()) { 1803 this.setDescription("${description}"); 1804 } 1805 1806 Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); 1807 if (subHyperlinkElement != null) { 1808 this.subHyperlink = new SubHyperlink(subHyperlinkElement); 1809 } 1810 } 1811 1812 1815 public String getDescription(Map context) { 1816 GenericValue value = null; 1818 String fieldKey = this.keyFieldName; 1819 if (UtilValidate.isEmpty(fieldKey)) { 1820 fieldKey = this.modelFormField.fieldName; 1821 } 1822 GenericDelegator delegator = this.modelFormField.modelForm.getDelegator(); 1823 String fieldValue = modelFormField.getEntry(context); 1824 try { 1825 if (this.cache) { 1826 value = delegator.findByPrimaryKeyCache(this.entityName, UtilMisc.toMap(fieldKey, fieldValue)); 1827 } else { 1828 value = delegator.findByPrimaryKey(this.entityName, UtilMisc.toMap(fieldKey, fieldValue)); 1829 } 1830 } catch (GenericEntityException e) { 1831 String errMsg = "Error getting value from the database for display of field [" + this.modelFormField.getName() + "] on form [" + this.modelFormField.modelForm.getName() + "]: " + e.toString(); 1832 Debug.logError(e, errMsg, module); 1833 throw new IllegalArgumentException (errMsg); 1834 } 1835 1836 String retVal = null; 1837 if (value != null) { 1838 retVal = this.description.expandString(value); 1839 } 1840 if (retVal == null || retVal.length() == 0) { 1842 retVal = fieldValue; 1843 } 1844 if (retVal == null || retVal.length() == 0) { 1845 retVal = " "; 1846 } 1847 return retVal; 1848 } 1849 1850 public SubHyperlink getSubHyperlink() { 1851 return this.subHyperlink; 1852 } 1853 public void setSubHyperlink(SubHyperlink newSubHyperlink) { 1854 this.subHyperlink = newSubHyperlink; 1855 } 1856 } 1857 1858 public static class HyperlinkField extends FieldInfo { 1859 public static String DEFAULT_TARGET_TYPE = "intra-app"; 1860 1861 protected boolean alsoHidden = true; 1862 protected String targetType; 1863 protected FlexibleStringExpander target; 1864 protected FlexibleStringExpander description; 1865 protected FlexibleStringExpander targetWindowExdr; 1866 1867 protected HyperlinkField() { 1868 super(); 1869 } 1870 1871 public HyperlinkField(ModelFormField modelFormField) { 1872 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.HYPERLINK, modelFormField); 1873 } 1874 1875 public HyperlinkField(int fieldSource, ModelFormField modelFormField) { 1876 super(fieldSource, FieldInfo.HYPERLINK, modelFormField); 1877 } 1878 1879 public HyperlinkField(Element element, ModelFormField modelFormField) { 1880 super(element, modelFormField); 1881 1882 this.setDescription(element.getAttribute("description")); 1883 this.setTarget(element.getAttribute("target")); 1884 this.alsoHidden = !"false".equals(element.getAttribute("also-hidden")); 1885 this.targetType = element.getAttribute("target-type"); 1886 this.targetWindowExdr = new FlexibleStringExpander(element.getAttribute("target-window")); 1887 } 1888 1889 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 1890 formStringRenderer.renderHyperlinkField(buffer, context, this); 1891 } 1892 1893 1896 public boolean getAlsoHidden() { 1897 return this.alsoHidden; 1898 } 1899 1900 1903 public String getTargetType() { 1904 if (UtilValidate.isNotEmpty(this.targetType)) { 1905 return this.targetType; 1906 } else { 1907 return HyperlinkField.DEFAULT_TARGET_TYPE; 1908 } 1909 } 1910 1911 public String getTargetWindow(Map context) { 1912 String targetWindow = this.targetWindowExdr.expandString(context); 1913 return targetWindow; 1914 } 1915 1916 1919 public String getDescription(Map context) { 1920 return this.description.expandString(context); 1921 } 1922 1923 1926 public String getTarget(Map context) { 1927 return this.target.expandString(context); 1928 } 1929 1930 1933 public void setAlsoHidden(boolean b) { 1934 this.alsoHidden = b; 1935 } 1936 1937 1940 public void setTargetType(String string) { 1941 this.targetType = string; 1942 } 1943 1944 1947 public void setDescription(String string) { 1948 this.description = new FlexibleStringExpander(string); 1949 } 1950 1951 1954 public void setTarget(String string) { 1955 this.target = new FlexibleStringExpander(string); 1956 } 1957 } 1958 1959 public static class SubHyperlink { 1960 protected FlexibleStringExpander useWhen; 1961 protected String linkStyle; 1962 protected String targetType; 1963 protected FlexibleStringExpander target; 1964 protected FlexibleStringExpander description; 1965 protected FlexibleStringExpander targetWindowExdr; 1966 1967 public SubHyperlink(Element element) { 1968 this.setDescription(element.getAttribute("description")); 1969 this.setTarget(element.getAttribute("target")); 1970 this.setUseWhen(element.getAttribute("use-when")); 1971 this.linkStyle = element.getAttribute("link-style"); 1972 this.targetType = element.getAttribute("target-type"); 1973 this.targetWindowExdr = new FlexibleStringExpander(element.getAttribute("target-window")); 1974 } 1975 1976 1979 public String getLinkStyle() { 1980 return this.linkStyle; 1981 } 1982 1983 1986 public String getTargetType() { 1987 if (UtilValidate.isNotEmpty(this.targetType)) { 1988 return this.targetType; 1989 } else { 1990 return HyperlinkField.DEFAULT_TARGET_TYPE; 1991 } 1992 } 1993 1994 1997 public String getDescription(Map context) { 1998 if (this.description != null) { 1999 return this.description.expandString(context); 2000 } else { 2001 return ""; 2002 } 2003 } 2004 2005 public String getTargetWindow(Map context) { 2006 String targetWindow = this.targetWindowExdr.expandString(context); 2007 return targetWindow; 2008 } 2009 2010 2013 public String getTarget(Map context) { 2014 if (this.target != null) { 2015 return this.target.expandString(context); 2016 } else { 2017 return ""; 2018 } 2019 } 2020 2021 2024 public String getUseWhen(Map context) { 2025 if (this.useWhen != null) { 2026 return this.useWhen.expandString(context); 2027 } else { 2028 return ""; 2029 } 2030 } 2031 2032 public boolean shouldUse(Map context) { 2033 boolean shouldUse = true; 2034 String useWhen = this.getUseWhen(context); 2035 if (UtilValidate.isNotEmpty(useWhen)) { 2036 try { 2037 Interpreter bsh = (Interpreter) context.get("bshInterpreter"); 2038 if (bsh == null) { 2039 bsh = BshUtil.makeInterpreter(context); 2040 context.put("bshInterpreter", bsh); 2041 } 2042 2043 Object retVal = bsh.eval(useWhen); 2044 2045 if (retVal instanceof Boolean ) { 2047 Boolean boolVal = (Boolean ) retVal; 2048 shouldUse = boolVal.booleanValue(); 2049 } else { 2050 throw new IllegalArgumentException ( 2051 "Return value from target condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "]"); 2052 } 2053 } catch (EvalError e) { 2054 String errmsg = "Error evaluating BeanShell target conditions"; 2055 Debug.logError(e, errmsg, module); 2056 throw new IllegalArgumentException (errmsg); 2057 } 2058 } 2059 return shouldUse; 2060 } 2061 2062 2065 public void setLinkStyle(String string) { 2066 this.linkStyle = string; 2067 } 2068 2069 2072 public void setTargetType(String string) { 2073 this.targetType = string; 2074 } 2075 2076 2079 public void setDescription(String string) { 2080 this.description = new FlexibleStringExpander(string); 2081 } 2082 2083 2086 public void setTarget(String string) { 2087 this.target = new FlexibleStringExpander(string); 2088 } 2089 2090 2093 public void setUseWhen(String string) { 2094 this.useWhen = new FlexibleStringExpander(string); 2095 } 2096 } 2097 2098 public static class TextField extends FieldInfo { 2099 protected int size = 25; 2100 protected Integer maxlength; 2101 protected FlexibleStringExpander defaultValue; 2102 protected SubHyperlink subHyperlink; 2103 protected boolean disabled; 2104 2105 protected TextField() { 2106 super(); 2107 } 2108 2109 public TextField(ModelFormField modelFormField) { 2110 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.TEXT, modelFormField); 2111 } 2112 2113 public TextField(int fieldSource, ModelFormField modelFormField) { 2114 super(fieldSource, FieldInfo.TEXT, modelFormField); 2115 } 2116 2117 public TextField(Element element, ModelFormField modelFormField) { 2118 super(element, modelFormField); 2119 this.setDefaultValue(element.getAttribute("default-value")); 2120 2121 String sizeStr = element.getAttribute("size"); 2122 try { 2123 size = Integer.parseInt(sizeStr); 2124 } catch (Exception e) { 2125 if (sizeStr != null && sizeStr.length() > 0) { 2126 Debug.logError("Could not parse the size value of the text element: [" + sizeStr + "], setting to the default of " + size, module); 2127 } 2128 } 2129 2130 String maxlengthStr = element.getAttribute("maxlength"); 2131 try { 2132 maxlength = Integer.valueOf(maxlengthStr); 2133 } catch (Exception e) { 2134 maxlength = null; 2135 if (maxlengthStr != null && maxlengthStr.length() > 0) { 2136 Debug.logError("Could not parse the max-length value of the text element: [" + maxlengthStr + "], setting to null; default of no maxlength will be used", module); 2137 } 2138 } 2139 2140 this.disabled = "true".equals(element.getAttribute("disabled")); 2141 2142 Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); 2143 if (subHyperlinkElement != null) { 2144 this.subHyperlink = new SubHyperlink(subHyperlinkElement); 2145 } 2146 } 2147 2148 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2149 formStringRenderer.renderTextField(buffer, context, this); 2150 } 2151 2152 2155 public Integer getMaxlength() { 2156 return maxlength; 2157 } 2158 2159 2162 public int getSize() { 2163 return size; 2164 } 2165 2166 2169 public boolean getDisabled() { 2170 return this.disabled; 2171 } 2172 2173 public void setDisabled(boolean b) { 2174 this.disabled = b; 2175 } 2176 2177 2178 2181 public String getDefaultValue(Map context) { 2182 if (this.defaultValue != null) { 2183 return this.defaultValue.expandString(context); 2184 } else { 2185 return ""; 2186 } 2187 } 2188 2189 2192 public void setMaxlength(Integer integer) { 2193 maxlength = integer; 2194 } 2195 2196 2199 public void setSize(int i) { 2200 size = i; 2201 } 2202 2203 2206 public void setDefaultValue(String str) { 2207 this.defaultValue = new FlexibleStringExpander(str); 2208 } 2209 2210 public SubHyperlink getSubHyperlink() { 2211 return this.subHyperlink; 2212 } 2213 public void setSubHyperlink(SubHyperlink newSubHyperlink) { 2214 this.subHyperlink = newSubHyperlink; 2215 } 2216 } 2217 2218 public static class TextareaField extends FieldInfo { 2219 protected int cols = 60; 2220 protected int rows = 2; 2221 protected FlexibleStringExpander defaultValue; 2222 protected boolean visualEditorEnable = false; 2223 protected FlexibleStringExpander visualEditorButtons; 2224 2225 protected TextareaField() { 2226 super(); 2227 } 2228 2229 public TextareaField(ModelFormField modelFormField) { 2230 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.TEXTAREA, modelFormField); 2231 } 2232 2233 public TextareaField(int fieldSource, ModelFormField modelFormField) { 2234 super(fieldSource, FieldInfo.TEXTAREA, modelFormField); 2235 } 2236 2237 public TextareaField(Element element, ModelFormField modelFormField) { 2238 super(element, modelFormField); 2239 this.setDefaultValue(element.getAttribute("default-value")); 2240 2241 visualEditorEnable = "true".equals(element.getAttribute("visual-editor-enable")); 2242 visualEditorButtons = new FlexibleStringExpander(element.getAttribute("visual-editor-buttons")); 2243 2244 String colsStr = element.getAttribute("cols"); 2245 try { 2246 cols = Integer.parseInt(colsStr); 2247 } catch (Exception e) { 2248 if (colsStr != null && colsStr.length() > 0) { 2249 Debug.logError("Could not parse the size value of the text element: [" + colsStr + "], setting to default of " + cols, module); 2250 } 2251 } 2252 2253 String rowsStr = element.getAttribute("rows"); 2254 try { 2255 rows = Integer.parseInt(rowsStr); 2256 } catch (Exception e) { 2257 if (rowsStr != null && rowsStr.length() > 0) { 2258 Debug.logError("Could not parse the size value of the text element: [" + rowsStr + "], setting to default of " + rows, module); 2259 } 2260 } 2261 } 2262 2263 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2264 formStringRenderer.renderTextareaField(buffer, context, this); 2265 } 2266 2267 2270 public int getCols() { 2271 return cols; 2272 } 2273 2274 2277 public int getRows() { 2278 return rows; 2279 } 2280 2281 2284 public String getDefaultValue(Map context) { 2285 if (this.defaultValue != null) { 2286 return this.defaultValue.expandString(context); 2287 } else { 2288 return ""; 2289 } 2290 } 2291 2292 2295 public boolean getVisualEditorEnable() { 2296 return this.visualEditorEnable; 2297 } 2298 2299 2302 public String getVisualEditorButtons(Map context) { 2303 return this.visualEditorButtons.expandString(context); 2304 } 2305 2306 2309 public void setCols(int i) { 2310 cols = i; 2311 } 2312 2313 2316 public void setRows(int i) { 2317 rows = i; 2318 } 2319 2320 2323 public void setDefaultValue(String str) { 2324 this.defaultValue = new FlexibleStringExpander(str); 2325 } 2326 2327 2330 public void setVisualEditorEnable(boolean visualEditorEnable) { 2331 this.visualEditorEnable = visualEditorEnable; 2332 } 2333 2334 2337 public void setVisualEditorButtons(String eb) { 2338 this.visualEditorButtons = new FlexibleStringExpander(eb); 2339 } 2340 } 2341 2342 public static class DateTimeField extends FieldInfo { 2343 protected String type; 2344 protected FlexibleStringExpander defaultValue; 2345 protected String inputMethod; 2346 protected String clock; 2347 2348 protected DateTimeField() { 2349 super(); 2350 } 2351 2352 public DateTimeField(ModelFormField modelFormField) { 2353 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DATE_TIME, modelFormField); 2354 } 2355 2356 public DateTimeField(int fieldSource, ModelFormField modelFormField) { 2357 super(fieldSource, FieldInfo.DATE_TIME, modelFormField); 2358 } 2359 2360 public DateTimeField(Element element, ModelFormField modelFormField) { 2361 super(element, modelFormField); 2362 this.setDefaultValue(element.getAttribute("default-value")); 2363 type = element.getAttribute("type"); 2364 inputMethod = element.getAttribute("input-method"); 2365 clock = element.getAttribute("clock"); 2366 } 2367 2368 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2369 formStringRenderer.renderDateTimeField(buffer, context, this); 2370 } 2371 2372 2375 public String getType() { 2376 return type; 2377 } 2378 2379 2382 public String getDefaultValue(Map context) { 2383 if (this.defaultValue != null) { 2384 return this.defaultValue.expandString(context); 2385 } else { 2386 return ""; 2387 } 2388 } 2389 2390 public String getInputMethod() { 2391 return this.inputMethod; 2392 } 2393 2394 public String getClock() { 2395 return this.clock; 2396 } 2397 2398 2401 public void setType(String string) { 2402 type = string; 2403 } 2404 2405 2408 public void setDefaultValue(String str) { 2409 this.defaultValue = new FlexibleStringExpander(str); 2410 } 2411 2412 public void setInputMethod(String str) { 2413 this.inputMethod = str; 2414 } 2415 2416 public void setClock(String str) { 2417 this.clock = str; 2418 } 2419 2420 2426 public String getDefaultDateTimeString(Map context) { 2427 if (this.defaultValue != null && !this.defaultValue.isEmpty()) { 2428 return this.getDefaultValue(context); 2429 } 2430 2431 if ("date".equals(this.type)) { 2432 return (new java.sql.Date (System.currentTimeMillis())).toString(); 2433 } else if ("time".equals(this.type)) { 2434 return (new java.sql.Time (System.currentTimeMillis())).toString(); 2435 } else { 2436 return UtilDateTime.nowTimestamp().toString(); 2437 } 2438 } 2439 } 2440 2441 public static class DropDownField extends FieldInfoWithOptions { 2442 protected boolean allowEmpty = false; 2443 protected String current; 2444 protected FlexibleStringExpander currentDescription; 2445 protected SubHyperlink subHyperlink; 2446 protected int otherFieldSize = 0; 2447 2448 protected DropDownField() { 2449 super(); 2450 } 2451 2452 public DropDownField(ModelFormField modelFormField) { 2453 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DROP_DOWN, modelFormField); 2454 } 2455 2456 public DropDownField(int fieldSource, ModelFormField modelFormField) { 2457 super(fieldSource, FieldInfo.DROP_DOWN, modelFormField); 2458 } 2459 2460 public DropDownField(Element element, ModelFormField modelFormField) { 2461 super(element, modelFormField); 2462 2463 this.current = element.getAttribute("current"); 2464 this.allowEmpty = "true".equals(element.getAttribute("allow-empty")); 2465 this.currentDescription = new FlexibleStringExpander(element.getAttribute("current-description")); 2466 2467 String sizeStr = element.getAttribute("other-field-size"); 2468 try { 2469 this.otherFieldSize = Integer.parseInt(sizeStr); 2470 } catch (Exception e) { 2471 if (sizeStr != null && sizeStr.length() > 0) { 2472 Debug.logError("Could not parse the size value of the text element: [" + sizeStr + "], setting to the default of " + this.otherFieldSize, module); 2473 } 2474 } 2475 2476 Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); 2477 if (subHyperlinkElement != null) { 2478 this.subHyperlink = new SubHyperlink(subHyperlinkElement); 2479 } 2480 } 2481 2482 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2483 formStringRenderer.renderDropDownField(buffer, context, this); 2484 } 2485 2486 public boolean isAllowEmpty() { 2487 return this.allowEmpty; 2488 } 2489 2490 public String getCurrent() { 2491 if (UtilValidate.isEmpty(this.current)) { 2492 return "first-in-list"; 2493 } else { 2494 return this.current; 2495 } 2496 } 2497 2498 public String getCurrentDescription(Map context) { 2499 if (this.currentDescription == null) 2500 return null; 2501 else 2502 return this.currentDescription.expandString(context); 2503 } 2504 2505 public void setAllowEmpty(boolean b) { 2506 this.allowEmpty = b; 2507 } 2508 2509 public void setCurrent(String string) { 2510 this.current = string; 2511 } 2512 2513 public void setCurrentDescription(String string) { 2514 this.currentDescription = new FlexibleStringExpander(string); 2515 } 2516 2517 public SubHyperlink getSubHyperlink() { 2518 return this.subHyperlink; 2519 } 2520 public void setSubHyperlink(SubHyperlink newSubHyperlink) { 2521 this.subHyperlink = newSubHyperlink; 2522 } 2523 2524 public int getOtherFieldSize() { 2525 return this.otherFieldSize; 2526 } 2527 2528 2534 public String getParameterNameOther(Map context) { 2535 String baseName; 2536 if (UtilValidate.isNotEmpty(this.modelFormField.parameterName)) { 2537 baseName = this.modelFormField.parameterName; 2538 } else { 2539 baseName = this.modelFormField.name; 2540 } 2541 2542 baseName += "_OTHER"; 2543 Integer itemIndex = (Integer ) context.get("itemIndex"); 2544 if (itemIndex != null && "multi".equals(this.modelFormField.modelForm.getType())) { 2545 return baseName + this.modelFormField.modelForm.getItemIndexSeparator() + itemIndex.intValue(); 2546 } else { 2547 return baseName; 2548 } 2549 } 2550 2551 } 2552 2553 public static class RadioField extends FieldInfoWithOptions { 2554 protected RadioField() { 2555 super(); 2556 } 2557 2558 public RadioField(ModelFormField modelFormField) { 2559 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.RADIO, modelFormField); 2560 } 2561 2562 public RadioField(int fieldSource, ModelFormField modelFormField) { 2563 super(fieldSource, FieldInfo.RADIO, modelFormField); 2564 } 2565 2566 public RadioField(Element element, ModelFormField modelFormField) { 2567 super(element, modelFormField); 2568 } 2569 2570 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2571 formStringRenderer.renderRadioField(buffer, context, this); 2572 } 2573 } 2574 2575 public static class CheckField extends FieldInfo { 2576 public final static String ROW_SUBMIT_FIELD_NAME = "_rowSubmit"; 2577 2578 protected CheckField() { 2579 super(); 2580 } 2581 2582 public CheckField(ModelFormField modelFormField) { 2583 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.CHECK, modelFormField); 2584 } 2585 2586 public CheckField(int fieldSource, ModelFormField modelFormField) { 2587 super(fieldSource, FieldInfo.CHECK, modelFormField); 2588 } 2589 2590 public CheckField(Element element, ModelFormField modelFormField) { 2591 super(element, modelFormField); 2592 } 2593 2594 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2595 formStringRenderer.renderCheckField(buffer, context, this); 2596 } 2597 } 2598 2599 public static class SubmitField extends FieldInfo { 2600 protected String buttonType; 2601 protected String imageLocation; 2602 2603 protected SubmitField() { 2604 super(); 2605 } 2606 2607 public SubmitField(ModelFormField modelFormField) { 2608 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.SUBMIT, modelFormField); 2609 } 2610 2611 public SubmitField(int fieldInfo, ModelFormField modelFormField) { 2612 super(fieldInfo, FieldInfo.SUBMIT, modelFormField); 2613 } 2614 2615 public SubmitField(Element element, ModelFormField modelFormField) { 2616 super(element, modelFormField); 2617 this.buttonType = element.getAttribute("button-type"); 2618 this.imageLocation = element.getAttribute("image-location"); 2619 } 2620 2621 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2622 formStringRenderer.renderSubmitField(buffer, context, this); 2623 } 2624 2625 2628 public String getButtonType() { 2629 return buttonType; 2630 } 2631 2632 2635 public String getImageLocation() { 2636 return imageLocation; 2637 } 2638 2639 2642 public void setButtonType(String string) { 2643 buttonType = string; 2644 } 2645 2646 2649 public void setImageLocation(String string) { 2650 imageLocation = string; 2651 } 2652 } 2653 2654 public static class ResetField extends FieldInfo { 2655 protected ResetField() { 2656 super(); 2657 } 2658 2659 public ResetField(ModelFormField modelFormField) { 2660 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.RESET, modelFormField); 2661 } 2662 2663 public ResetField(int fieldSource, ModelFormField modelFormField) { 2664 super(fieldSource, FieldInfo.RESET, modelFormField); 2665 } 2666 2667 public ResetField(Element element, ModelFormField modelFormField) { 2668 super(element, modelFormField); 2669 } 2670 2671 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2672 formStringRenderer.renderResetField(buffer, context, this); 2673 } 2674 } 2675 2676 public static class HiddenField extends FieldInfo { 2677 protected FlexibleStringExpander value; 2678 2679 protected HiddenField() { 2680 super(); 2681 } 2682 2683 public HiddenField(ModelFormField modelFormField) { 2684 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.HIDDEN, modelFormField); 2685 } 2686 2687 public HiddenField(int fieldSource, ModelFormField modelFormField) { 2688 super(fieldSource, FieldInfo.HIDDEN, modelFormField); 2689 } 2690 2691 public HiddenField(Element element, ModelFormField modelFormField) { 2692 super(element, modelFormField); 2693 this.setValue(element.getAttribute("value")); 2694 } 2695 2696 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2697 formStringRenderer.renderHiddenField(buffer, context, this); 2698 } 2699 2700 public String getValue(Map context) { 2701 if (this.value != null && !this.value.isEmpty()) { 2702 return this.value.expandString(context); 2703 } else { 2704 return modelFormField.getEntry(context); 2705 } 2706 } 2707 2708 public void setValue(String string) { 2709 this.value = new FlexibleStringExpander(string); 2710 } 2711 } 2712 2713 public static class IgnoredField extends FieldInfo { 2714 protected IgnoredField() { 2715 super(); 2716 } 2717 2718 public IgnoredField(ModelFormField modelFormField) { 2719 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.IGNORED, modelFormField); 2720 } 2721 2722 public IgnoredField(int fieldSource, ModelFormField modelFormField) { 2723 super(fieldSource, FieldInfo.IGNORED, modelFormField); 2724 } 2725 2726 public IgnoredField(Element element, ModelFormField modelFormField) { 2727 super(element, modelFormField); 2728 } 2729 2730 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2731 formStringRenderer.renderIgnoredField(buffer, context, this); 2732 } 2733 } 2734 2735 public static class TextFindField extends TextField { 2736 protected boolean ignoreCase = true; 2737 protected String defaultOption = "like"; 2738 2739 public TextFindField(Element element, ModelFormField modelFormField) { 2740 super(element, modelFormField); 2741 this.ignoreCase = "true".equals(element.getAttribute("ignore-case")); 2742 this.defaultOption = element.getAttribute("default-option"); 2743 } 2744 2745 public TextFindField(int fieldSource, ModelFormField modelFormField) { 2746 super(fieldSource, modelFormField); 2747 } 2748 2749 public boolean getIgnoreCase() { 2750 return this.ignoreCase; 2751 } 2752 2753 public String getDefaultOption() { 2754 return this.defaultOption; 2755 } 2756 2757 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2758 formStringRenderer.renderTextFindField(buffer, context, this); 2759 } 2760 } 2761 2762 public static class DateFindField extends DateTimeField { 2763 public DateFindField(Element element, ModelFormField modelFormField) { 2764 super(element, modelFormField); 2765 } 2766 2767 public DateFindField(int fieldSource, ModelFormField modelFormField) { 2768 super(fieldSource, modelFormField); 2769 } 2770 2771 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2772 formStringRenderer.renderDateFindField(buffer, context, this); 2773 } 2774 } 2775 2776 public static class RangeFindField extends TextField { 2777 public RangeFindField(Element element, ModelFormField modelFormField) { 2778 super(element, modelFormField); 2779 } 2780 2781 public RangeFindField(int fieldSource, ModelFormField modelFormField) { 2782 super(fieldSource, modelFormField); 2783 } 2784 2785 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2786 formStringRenderer.renderRangeFindField(buffer, context, this); 2787 } 2788 } 2789 2790 public static class LookupField extends TextField { 2791 protected FlexibleStringExpander formName; 2792 protected String descriptionFieldName; 2793 protected String targetParameter; 2794 2795 public LookupField(Element element, ModelFormField modelFormField) { 2796 super(element, modelFormField); 2797 this.formName = new FlexibleStringExpander(element.getAttribute("target-form-name")); 2798 this.descriptionFieldName = element.getAttribute("description-field-name"); 2799 this.targetParameter = element.getAttribute("target-parameter"); 2800 } 2801 2802 public LookupField(int fieldSource, ModelFormField modelFormField) { 2803 super(fieldSource, modelFormField); 2804 } 2805 2806 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2807 formStringRenderer.renderLookupField(buffer, context, this); 2808 } 2809 2810 public String getFormName(Map context) { 2811 return this.formName.expandString(context); 2812 } 2813 2814 public List getTargetParameterList() { 2815 List paramList = FastList.newInstance(); 2816 if (UtilValidate.isNotEmpty(this.targetParameter)) { 2817 StringTokenizer stk = new StringTokenizer (this.targetParameter, ", "); 2818 while (stk.hasMoreTokens()) { 2819 paramList.add(stk.nextToken()); 2820 } 2821 } 2822 return paramList; 2823 } 2824 2825 public void setFormName(String str) { 2826 this.formName = new FlexibleStringExpander(str); 2827 } 2828 2829 public String getDescriptionFieldName() { 2830 return this.descriptionFieldName; 2831 } 2832 2833 public void setDescriptionFieldName(String str) { 2834 this.descriptionFieldName = str; 2835 } 2836 } 2837 2838 public static class FileField extends TextField { 2839 2840 public FileField(Element element, ModelFormField modelFormField) { 2841 super(element, modelFormField); 2842 } 2843 2844 public FileField(int fieldSource, ModelFormField modelFormField) { 2845 super(fieldSource, modelFormField); 2846 } 2847 2848 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2849 formStringRenderer.renderFileField(buffer, context, this); 2850 } 2851 } 2852 2853 public static class PasswordField extends TextField { 2854 2855 public PasswordField(Element element, ModelFormField modelFormField) { 2856 super(element, modelFormField); 2857 } 2858 2859 public PasswordField(int fieldSource, ModelFormField modelFormField) { 2860 super(fieldSource, modelFormField); 2861 } 2862 2863 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2864 formStringRenderer.renderPasswordField(buffer, context, this); 2865 } 2866 } 2867 2868 public static class ImageField extends FieldInfo { 2869 protected int border = 0; 2870 protected Integer width; 2871 protected Integer height; 2872 protected FlexibleStringExpander defaultValue; 2873 protected FlexibleStringExpander value; 2874 protected SubHyperlink subHyperlink; 2875 2876 protected ImageField() { 2877 super(); 2878 } 2879 2880 public ImageField(ModelFormField modelFormField) { 2881 super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.IMAGE, modelFormField); 2882 } 2883 2884 public ImageField(int fieldSource, ModelFormField modelFormField) { 2885 super(fieldSource, FieldInfo.IMAGE, modelFormField); 2886 } 2887 2888 public ImageField(Element element, ModelFormField modelFormField) { 2889 super(element, modelFormField); 2890 this.setValue(element.getAttribute("value")); 2891 2892 String borderStr = element.getAttribute("border"); 2893 try { 2894 border = Integer.parseInt(borderStr); 2895 } catch (Exception e) { 2896 if (borderStr != null && borderStr.length() > 0) { 2897 Debug.logError("Could not parse the border value of the text element: [" + borderStr + "], setting to the default of " + border, module); 2898 } 2899 } 2900 2901 String widthStr = element.getAttribute("width"); 2902 try { 2903 width = Integer.valueOf(widthStr); 2904 } catch (Exception e) { 2905 width = null; 2906 if (widthStr != null && widthStr.length() > 0) { 2907 Debug.logError( 2908 "Could not parse the size value of the text element: [" + widthStr + "], setting to null; default of no width will be used", 2909 module); 2910 } 2911 } 2912 2913 String heightStr = element.getAttribute("height"); 2914 try { 2915 height = Integer.valueOf(heightStr); 2916 } catch (Exception e) { 2917 height = null; 2918 if (heightStr != null && heightStr.length() > 0) { 2919 Debug.logError( 2920 "Could not parse the size value of the text element: [" + heightStr + "], setting to null; default of no height will be used", 2921 module); 2922 } 2923 } 2924 2925 Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); 2926 if (subHyperlinkElement != null) { 2927 this.subHyperlink = new SubHyperlink(subHyperlinkElement); 2928 } 2929 } 2930 2931 public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { 2932 formStringRenderer.renderImageField(buffer, context, this); 2933 } 2934 2935 2936 2939 public void setDefaultValue(String str) { 2940 this.defaultValue = new FlexibleStringExpander(str); 2941 } 2942 2943 public SubHyperlink getSubHyperlink() { 2944 return this.subHyperlink; 2945 } 2946 public void setSubHyperlink(SubHyperlink newSubHyperlink) { 2947 this.subHyperlink = newSubHyperlink; 2948 } 2949 2952 public Integer getWidth() { 2953 return width; 2954 } 2955 2958 public Integer getHeight() { 2959 return height; 2960 } 2961 2962 2965 public int getBorder() { 2966 return border; 2967 } 2968 2969 2972 public String getDefaultValue(Map context) { 2973 if (this.defaultValue != null) { 2974 return this.defaultValue.expandString(context); 2975 } else { 2976 return ""; 2977 } 2978 } 2979 2980 public String getValue(Map context) { 2981 if (this.value != null && !this.value.isEmpty()) { 2982 return this.value.expandString(context); 2983 } else { 2984 return modelFormField.getEntry(context); 2985 } 2986 } 2987 2988 public void setValue(String string) { 2989 this.value = new FlexibleStringExpander(string); 2990 } 2991 2992 } 2993} 2994 | Popular Tags |