📄 htmlformrenderer.java
字号:
buffer.append("htmlEditArea"); buffer.append('"'); } buffer.append('>'); String value = modelFormField.getEntry(context, textareaField.getDefaultValue(context)); if (UtilValidate.isNotEmpty(value)) { buffer.append(value); } buffer.append("</textarea>"); if (textareaField.getVisualEditorEnable()) { buffer.append("<script language=\"javascript\" src=\"/images/htmledit/whizzywig.js\" type=\"text/javascript\"></script>"); buffer.append("<script language=\"javascript\" type=\"text/javascript\"> buttonPath = \"/images/htmledit/\"; cssFile=\"/images/htmledit/simple.css\";makeWhizzyWig(\""); if (UtilValidate.isNotEmpty(idName)) { buffer.append(idName); } else { buffer.append("htmlEditArea"); } buffer.append("\",\""); String buttons = textareaField.getVisualEditorButtons(context); if (UtilValidate.isNotEmpty(buttons)) { buffer.append(buttons); } else { buffer.append("all"); } buffer.append("\") </script>"); } this.addAstericks(buffer, context, modelFormField); this.appendTooltip(buffer, context, modelFormField); this.appendWhitespace(buffer); } /* (non-Javadoc) * @see org.ofbiz.widget.form.FormStringRenderer#renderDateTimeField(java.lang.StringBuffer, java.util.Map, org.ofbiz.widget.form.ModelFormField.DateTimeField) */ public void renderDateTimeField(StringBuffer buffer, Map context, DateTimeField dateTimeField) { ModelFormField modelFormField = dateTimeField.getModelFormField(); String paramName = modelFormField.getParameterName(context); String defaultDateTimeString = dateTimeField.getDefaultDateTimeString(context); // whether the date field is short form, yyyy-mm-dd boolean shortDateInput = ("date".equals(dateTimeField.getType()) || "time-dropdown".equals(dateTimeField.getInputMethod()) ? true : false); buffer.append("<input type=\"text\""); String className = modelFormField.getWidgetStyle(); if (UtilValidate.isNotEmpty(className)) { buffer.append(" class=\""); buffer.append(className); buffer.append('"'); } // add a style of red if this is a date/time field and redWhen is true if (modelFormField.shouldBeRed(context)) { buffer.append(" style=\"color: red;\""); } buffer.append(" name=\""); if ("time-dropdown".equals(dateTimeField.getInputMethod())) { buffer.append(UtilHttp.makeCompositeParam(paramName, "date")); } else { buffer.append(paramName); } buffer.append('"'); String value = modelFormField.getEntry(context, dateTimeField.getDefaultValue(context)); if (UtilValidate.isNotEmpty(value)) { buffer.append(" value=\""); if ("date".equals(dateTimeField.getType()) && value.length()>=10) { value = value.substring(0, 10); } else if ("time".equals(dateTimeField.getType()) && value.length()>=16) { value = value.substring(0, 16); } buffer.append(value); buffer.append('"'); } // the default values for a timestamp int size = 25; int maxlength = 30; if (shortDateInput) { size = 10; maxlength = 10; } else if ("time".equals(dateTimeField.getType())) { size = 16; maxlength = 16; } buffer.append(" size=\""); buffer.append(size); buffer.append('"'); buffer.append(" maxlength=\""); buffer.append(maxlength); buffer.append('"'); String idName = modelFormField.getIdName(); if (UtilValidate.isNotEmpty(idName)) { buffer.append(" id=\""); buffer.append(idName); buffer.append('"'); } buffer.append("/>"); // add calendar pop-up button and seed data IF this is not a "time" type date-time if (!"time".equals(dateTimeField.getType())) { if (shortDateInput) { buffer.append("<a href=\"javascript:call_cal_notime(document."); } else { buffer.append("<a href=\"javascript:call_cal(document."); } buffer.append(modelFormField.getModelForm().getCurrentFormName(context)); buffer.append('.'); if ("time-dropdown".equals(dateTimeField.getInputMethod())) buffer.append(UtilHttp.makeCompositeParam(paramName, "date")); else { buffer.append(paramName); } buffer.append(",'"); buffer.append(UtilHttp.encodeBlanks(modelFormField.getEntry(context, defaultDateTimeString))); buffer.append("');\">"); buffer.append("<img src=\""); this.appendContentUrl(buffer, "/content/images/cal.gif"); buffer.append("\" width=\"16\" height=\"16\" border=\"0\" alt=\"Calendar\"/></a>"); } // if we have an input method of time-dropdown, then render two dropdowns if ("time-dropdown".equals(dateTimeField.getInputMethod())) { String classString = (className != null ? " class=\"" + className + "\" " : ""); boolean isTwelveHour = "12".equals(dateTimeField.getClock()); // set the Calendar to the default time of the form or now() Calendar cal = null; try { Timestamp defaultTimestamp = Timestamp.valueOf(modelFormField.getEntry(context, defaultDateTimeString)); cal = Calendar.getInstance(); cal.setTime(defaultTimestamp); } catch (IllegalArgumentException e) { Debug.logWarning("Form widget field [" + paramName + "] with input-method=\"time-dropdown\" was not able to understand the default time [" + defaultDateTimeString + "]. The parsing error was: " + e.getMessage(), module); } // write the select for hours buffer.append(" <select name=\"").append(UtilHttp.makeCompositeParam(paramName, "hour")).append("\""); buffer.append(classString).append(">"); // keep the two cases separate because it's hard to unerstand a combined loop if (isTwelveHour) { for (int i = 1; i <= 12; i++) { buffer.append("<option value=\"").append(i).append("\""); if (cal != null) { int hour = cal.get(Calendar.HOUR_OF_DAY); if (hour == 0) hour = 12; if (hour > 12) hour -= 12; if (i == hour) buffer.append(" selected"); } buffer.append(">").append(i).append("</option>"); } } else { for (int i = 0; i < 24; i++) { buffer.append("<option value=\"").append(i).append("\""); if (cal != null && i == cal.get(Calendar.HOUR_OF_DAY)) { buffer.append(" selected"); } buffer.append(">").append(i).append("</option>"); } } // write the select for minutes buffer.append("</select>:<select name=\""); buffer.append(UtilHttp.makeCompositeParam(paramName, "minutes")).append("\""); buffer.append(classString).append(">"); for (int i = 0; i < 60; i++) { buffer.append("<option value=\"").append(i).append("\""); if (cal != null && i == cal.get(Calendar.MINUTE)) { buffer.append(" selected"); } buffer.append(">").append(i).append("</option>"); } buffer.append("</select>"); // if 12 hour clock, write the AM/PM selector if (isTwelveHour) { String amSelected = ((cal != null && cal.get(Calendar.AM_PM) == Calendar.AM) ? "selected" : ""); String pmSelected = ((cal != null && cal.get(Calendar.AM_PM) == Calendar.PM) ? "selected" : ""); buffer.append("<select name=\"").append(UtilHttp.makeCompositeParam(paramName, "ampm")).append("\""); buffer.append(classString).append(">"); buffer.append("<option value=\"").append("AM").append("\" ").append(amSelected).append(">AM</option>"); buffer.append("<option value=\"").append("PM").append("\" ").append(pmSelected).append(">PM</option>"); buffer.append("</select>"); } // create a hidden field for the composite type, which is a Timestamp buffer.append("<input type=\"hidden\" name=\""); buffer.append(UtilHttp.makeCompositeParam(paramName, "compositeType")); buffer.append("\" value=\"Timestamp\">"); } this.appendTooltip(buffer, context, modelFormField); this.appendWhitespace(buffer); } /* (non-Javadoc) * @see org.ofbiz.widget.form.FormStringRenderer#renderDropDownField(java.lang.StringBuffer, java.util.Map, org.ofbiz.widget.form.ModelFormField.DropDownField) */ public void renderDropDownField(StringBuffer buffer, Map context, DropDownField dropDownField) { ModelFormField modelFormField = dropDownField.getModelFormField(); ModelForm modelForm = modelFormField.getModelForm(); String event = modelFormField.getEvent(); String action = modelFormField.getAction(); buffer.append("<select"); String className = modelFormField.getWidgetStyle(); if (UtilValidate.isNotEmpty(className)) { buffer.append(" class=\""); buffer.append(className); buffer.append('"'); } buffer.append(" name=\""); buffer.append(modelFormField.getParameterName(context)); buffer.append('"'); String idName = modelFormField.getIdName(); if (UtilValidate.isNotEmpty(idName)) { buffer.append(" id=\""); buffer.append(idName); buffer.append('"'); } int otherFieldSize = dropDownField.getOtherFieldSize(); String otherFieldName = dropDownField.getParameterNameOther(context); if (otherFieldSize > 0) { //buffer.append(" onchange=\"alert('ONCHANGE, process_choice:' + process_choice)\""); //buffer.append(" onchange='test_js()' "); buffer.append(" onchange=\"process_choice(this,document."); buffer.append(modelForm.getName()); buffer.append("."); buffer.append(otherFieldName); buffer.append(")\" "); /* */ } if (UtilValidate.isNotEmpty(event) && UtilValidate.isNotEmpty(action)) { buffer.append(" "); buffer.append(event); buffer.append("=\""); buffer.append(action); buffer.append('"'); } buffer.append(" size=\"1\">"); String currentValue = modelFormField.getEntry(context); List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator()); // if the current value should go first, stick it in if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) { buffer.append("<option"); buffer.append(" selected=\"selected\""); buffer.append(" value=\""); buffer.append(currentValue); buffer.append("\">"); String explicitDescription = dropDownField.getCurrentDescription(context); if (UtilValidate.isNotEmpty(explicitDescription)) { buffer.append(explicitDescription); } else { buffer.append(ModelFormField.FieldInfoWithOptions.getDescriptionForOptionKey(currentValue, allOptionValues)); } buffer.append("</option>"); // add a "separator" option buffer.append("<option value=\""); buffer.append(currentValue); buffer.append("\">---</option>"); } // if allow empty is true, add an empty option if (dropDownField.isAllowEmpty()) { buffer.append("<option value=\"\"> </option>"); } // list out all options according to the option list Iterator optionValueIter = allOptionValues.iterator(); while (optionValueIter.hasNext()) { ModelFormField.OptionValue optionValue = (ModelFormField.OptionValue) optionValueIter.next(); String noCurrentSelectedKey = dropDownField.getNoCurrentSelectedKey(context); buffer.append("<option"); // if current value should be selected in the list, select it if (UtilValidate.isNotEmpty(currentValue) && currentValue.equals(optionValue.getKey()) && "selected".equals(dropDownField.getCurrent())) { buffer.append(" selected=\"selected\""); } else if (UtilValidate.isEmpty(currentValue) && noCurrentSelectedKey != null && noCurrentSelectedKey.equals(optionValue.getKey())) { buffer.append(" selected=\"selected\""); } buffer.append(" value=\""); buffer.append(optionValue.getKey()); buffer.append("\">"); buffer.append(optionValue.getDescription()); buffer.append("</option>"); } buffer.append("</select>");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -