/* (non-Javadoc)
* @see org.ofbiz.widget.form.FormStringRenderer#renderDisplayField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.DisplayField)
*/
public void renderDisplayField(Appendable writer, Map<String, Object> context, DisplayField displayField) throws IOException {
ModelFormField modelFormField = displayField.getModelFormField();
ModelForm modelForm = modelFormField.getModelForm();
StringBuffer str = new StringBuffer();
String idName = modelFormField.getIdName();
if (UtilValidate.isNotEmpty(idName) && ("list".equals(modelForm.getType()) || "multi".equals(modelForm.getType()))) {
idName += "_" + modelForm.getRowCount();
}
if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle()) || modelFormField.shouldBeRed(context)) {
str.append("<span class=\"");
str.append(modelFormField.getWidgetStyle());
str.append('"');
if (UtilValidate.isNotEmpty(idName)) {
str.append(" id=\"");
str.append(idName);
str.append('"');
}
// add a style of red if this is a date/time field and redWhen is true
if (modelFormField.shouldBeRed(context)) {
str.append(" alert");
}
str.append('>');
}
if (str.length() > 0) {
writer.append(str.toString());
}
String description = displayField.getDescription(context);
//Replace new lines with <br/>
description = description.replaceAll("\n", "<br/>");
if (UtilValidate.isEmpty(description)) {
this.renderFormatEmptySpace(writer, context, modelFormField.getModelForm());
} else {
writer.append(description);
}
if (str.length() > 0) {
writer.append("</span>");
}
ModelFormField.InPlaceEditor inPlaceEditor = displayField.getInPlaceEditor();
boolean ajaxEnabled = inPlaceEditor != null && this.javaScriptEnabled;
if (ajaxEnabled) {
writer.append("<script language=\"JavaScript\" type=\"text/javascript\">");
String url = inPlaceEditor.getUrl(context);
Map<String, Object> fieldMap = inPlaceEditor.getFieldMap(context);
if (fieldMap != null) {
url += '?';
Set<Entry<String, Object>> fieldSet = fieldMap.entrySet();
Iterator<Entry<String, Object>> fieldIterator = fieldSet.iterator();
int count = 0;
while (fieldIterator.hasNext()) {
count++;
Entry<String, Object> field = fieldIterator.next();
url += (String) field.getKey() + '=' + (String) field.getValue();
if (count < fieldSet.size()) {
url += '&';
}
}
}
writer.append("ajaxInPlaceEditDisplayField('");
writer.append(idName + "', '" +url+ "', {");
if (UtilValidate.isNotEmpty(inPlaceEditor.getParamName())) {
writer.append("paramName: '" +inPlaceEditor.getParamName()+ "'");
} else {
writer.append("paramName: '" +modelFormField.getFieldName()+ "'");
}
if (UtilValidate.isNotEmpty(inPlaceEditor.getCancelControl())) {
writer.append(", cancelControl: ");
if (!"false".equals(inPlaceEditor.getCancelControl())) {
writer.append("'");