use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class MacroFormRenderer method renderCheckField.
public void renderCheckField(Appendable writer, Map<String, Object> context, CheckField checkField) throws IOException {
ModelFormField modelFormField = checkField.getModelFormField();
String currentValue = modelFormField.getEntry(context);
String conditionGroup = modelFormField.getConditionGroup();
Boolean allChecked = checkField.isAllChecked(context);
String id = modelFormField.getCurrentContainerId(context);
String className = "";
String alert = "false";
String name = modelFormField.getParameterName(context);
String event = modelFormField.getEvent();
String action = modelFormField.getAction(context);
StringBuilder items = new StringBuilder();
if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
className = modelFormField.getWidgetStyle();
if (modelFormField.shouldBeRed(context)) {
alert = "true";
}
}
String tabindex = modelFormField.getTabindex();
List<ModelFormField.OptionValue> allOptionValues = checkField.getAllOptionValues(context, WidgetWorker.getDelegator(context));
items.append("[");
for (ModelFormField.OptionValue optionValue : allOptionValues) {
if (items.length() > 1) {
items.append(",");
}
items.append("{'value':'");
items.append(optionValue.getKey());
items.append("', 'description':'" + encode(optionValue.getDescription(), modelFormField, context));
items.append("'}");
}
items.append("]");
StringWriter sr = new StringWriter();
sr.append("<@renderCheckField ");
sr.append("items=");
sr.append(items.toString());
sr.append(" className=\"");
sr.append(className);
sr.append("\" alert=\"");
sr.append(alert);
sr.append("\" id=\"");
sr.append(id);
sr.append("\" conditionGroup=\"");
sr.append(conditionGroup);
sr.append("\" allChecked=");
sr.append((allChecked != null ? Boolean.toString(allChecked) : "\"\""));
sr.append(" currentValue=\"");
sr.append(currentValue);
sr.append("\" name=\"");
sr.append(name);
sr.append("\" event=\"");
if (event != null) {
sr.append(event);
}
sr.append("\" action=\"");
if (action != null) {
sr.append(action);
}
sr.append("\" tabindex=\"");
sr.append(tabindex);
sr.append("\" />");
executeMacro(writer, sr.toString());
this.appendTooltip(writer, context, modelFormField);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class MacroFormRenderer method renderDropDownField.
public void renderDropDownField(Appendable writer, Map<String, Object> context, DropDownField dropDownField) throws IOException {
ModelFormField modelFormField = dropDownField.getModelFormField();
ModelForm modelForm = modelFormField.getModelForm();
String currentValue = modelFormField.getEntry(context);
String conditionGroup = modelFormField.getConditionGroup();
List<ModelFormField.OptionValue> allOptionValues = dropDownField.getAllOptionValues(context, WidgetWorker.getDelegator(context));
ModelFormField.AutoComplete autoComplete = dropDownField.getAutoComplete();
String event = modelFormField.getEvent();
String action = modelFormField.getAction(context);
Integer textSize = Integer.valueOf(0);
if (UtilValidate.isNotEmpty(dropDownField.getTextSize())) {
try {
textSize = Integer.parseInt(dropDownField.getTextSize());
} catch (NumberFormatException nfe) {
Debug.logError(nfe, "Error reading size of a field fieldName=" + dropDownField.getModelFormField().getFieldName() + " FormName= " + dropDownField.getModelFormField().getModelForm().getName(), module);
}
if (textSize > 0 && UtilValidate.isNotEmpty(currentValue) && currentValue.length() > textSize) {
currentValue = currentValue.substring(0, textSize - 8) + "..." + currentValue.substring(currentValue.length() - 5);
}
}
boolean ajaxEnabled = autoComplete != null && this.javaScriptEnabled;
String className = "";
String alert = "false";
String name = modelFormField.getParameterName(context);
String id = modelFormField.getCurrentContainerId(context);
String multiple = dropDownField.getAllowMultiple() ? "multiple" : "";
String otherFieldName = "";
String formName = modelForm.getName();
String size = dropDownField.getSize();
String dDFCurrent = dropDownField.getCurrent();
String firstInList = "";
String explicitDescription = "";
String allowEmpty = "";
StringBuilder options = new StringBuilder();
StringBuilder ajaxOptions = new StringBuilder();
if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
className = modelFormField.getWidgetStyle();
if (modelFormField.shouldBeRed(context)) {
alert = "true";
}
}
// check for required field style on single forms
if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
String requiredStyle = modelFormField.getRequiredFieldStyle();
if (UtilValidate.isEmpty(requiredStyle)) {
requiredStyle = "required";
}
if (UtilValidate.isEmpty(className)) {
className = requiredStyle;
} else {
className = requiredStyle + " " + className;
}
}
String currentDescription = null;
if (UtilValidate.isNotEmpty(currentValue)) {
for (ModelFormField.OptionValue optionValue : allOptionValues) {
if (optionValue.getKey().equals(currentValue)) {
currentDescription = optionValue.getDescription();
break;
}
}
}
int otherFieldSize = dropDownField.getOtherFieldSize();
if (otherFieldSize > 0) {
otherFieldName = dropDownField.getParameterNameOther(context);
}
// if the current value should go first, stick it in
if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) {
firstInList = "first-in-list";
}
explicitDescription = (currentDescription != null ? currentDescription : dropDownField.getCurrentDescription(context));
if (UtilValidate.isEmpty(explicitDescription)) {
explicitDescription = (FieldInfoWithOptions.getDescriptionForOptionKey(currentValue, allOptionValues));
}
if (textSize > 0 && UtilValidate.isNotEmpty(explicitDescription) && explicitDescription.length() > textSize) {
explicitDescription = explicitDescription.substring(0, textSize - 8) + "..." + explicitDescription.substring(explicitDescription.length() - 5);
}
explicitDescription = encode(explicitDescription, modelFormField, context);
// if allow empty is true, add an empty option
if (dropDownField.getAllowEmpty()) {
allowEmpty = "Y";
}
List<String> currentValueList = null;
if (UtilValidate.isNotEmpty(currentValue) && dropDownField.getAllowMultiple()) {
// If currentValue is Array, it will start with [
if (currentValue.startsWith("[")) {
currentValueList = StringUtil.toList(currentValue);
} else {
currentValueList = UtilMisc.toList(currentValue);
}
}
options.append("[");
Iterator<ModelFormField.OptionValue> optionValueIter = allOptionValues.iterator();
int count = 0;
while (optionValueIter.hasNext()) {
ModelFormField.OptionValue optionValue = optionValueIter.next();
if (options.length() > 1) {
options.append(",");
}
options.append("{'key':'");
String key = encode(optionValue.getKey(), modelFormField, context);
options.append(key);
options.append("'");
options.append(",'description':'");
String description = optionValue.getDescription();
if (textSize > 0 && description.length() > textSize) {
description = description.substring(0, textSize - 8) + "..." + description.substring(description.length() - 5);
}
// replaceAll("'", "\\\\\'") related to OFBIZ-6504
options.append(encode(description.replaceAll("'", "\\\\\'"), modelFormField, context));
if (UtilValidate.isNotEmpty(currentValueList)) {
options.append("'");
options.append(",'selected':'");
if (currentValueList.contains(optionValue.getKey())) {
options.append("selected");
} else {
options.append("");
}
}
options.append("'}");
if (ajaxEnabled) {
count++;
ajaxOptions.append(optionValue.getKey()).append(": ");
ajaxOptions.append(" '").append(optionValue.getDescription()).append("'");
if (count != allOptionValues.size()) {
ajaxOptions.append(", ");
}
}
}
options.append("]");
String noCurrentSelectedKey = dropDownField.getNoCurrentSelectedKey(context);
String otherValue = "", fieldName = "";
// http://www.cs.tut.fi/~jkorpela/forms/combo.html
if (otherFieldSize > 0) {
fieldName = modelFormField.getParameterName(context);
Map<String, ? extends Object> dataMap = modelFormField.getMap(context);
if (dataMap == null) {
dataMap = context;
}
Object otherValueObj = dataMap.get(otherFieldName);
otherValue = (otherValueObj == null) ? "" : otherValueObj.toString();
}
String frequency = "";
String minChars = "";
String choices = "";
String autoSelect = "";
String partialSearch = "";
String partialChars = "";
String ignoreCase = "";
String fullSearch = "";
if (ajaxEnabled) {
frequency = autoComplete.getFrequency();
minChars = autoComplete.getMinChars();
choices = autoComplete.getChoices();
autoSelect = autoComplete.getAutoSelect();
partialSearch = autoComplete.getPartialSearch();
partialChars = autoComplete.getPartialChars();
ignoreCase = autoComplete.getIgnoreCase();
fullSearch = autoComplete.getFullSearch();
}
String tabindex = modelFormField.getTabindex();
StringWriter sr = new StringWriter();
sr.append("<@renderDropDownField ");
sr.append("name=\"");
sr.append(name);
sr.append("\" className=\"");
sr.append(className);
sr.append("\" alert=\"");
sr.append(alert);
sr.append("\" id=\"");
sr.append(id);
sr.append("\" multiple=\"");
sr.append(multiple);
sr.append("\" formName=\"");
sr.append(formName);
sr.append("\" otherFieldName=\"");
sr.append(otherFieldName);
sr.append("\" event=\"");
if (event != null) {
sr.append(event);
}
sr.append("\" action=\"");
if (action != null) {
sr.append(action);
}
sr.append("\" size=\"");
sr.append(size);
sr.append("\" firstInList=\"");
sr.append(firstInList);
sr.append("\" currentValue=\"");
sr.append(currentValue);
sr.append("\" explicitDescription=\"");
sr.append(explicitDescription);
sr.append("\" allowEmpty=\"");
sr.append(allowEmpty);
sr.append("\" options=");
sr.append(options.toString());
sr.append(" fieldName=\"");
sr.append(fieldName);
sr.append("\" otherFieldName=\"");
sr.append(otherFieldName);
sr.append("\" otherValue=\"");
sr.append(otherValue);
sr.append("\" otherFieldSize=");
sr.append(Integer.toString(otherFieldSize));
sr.append(" dDFCurrent=\"");
sr.append(dDFCurrent);
sr.append("\" ajaxEnabled=");
sr.append(Boolean.toString(ajaxEnabled));
sr.append(" noCurrentSelectedKey=\"");
sr.append(noCurrentSelectedKey);
sr.append("\" ajaxOptions=\"");
sr.append(ajaxOptions.toString());
sr.append("\" frequency=\"");
sr.append(frequency);
sr.append("\" minChars=\"");
sr.append(minChars);
sr.append("\" choices=\"");
sr.append(choices);
sr.append("\" autoSelect=\"");
sr.append(autoSelect);
sr.append("\" partialSearch=\"");
sr.append(partialSearch);
sr.append("\" partialChars=\"");
sr.append(partialChars);
sr.append("\" ignoreCase=\"");
sr.append(ignoreCase);
sr.append("\" fullSearch=\"");
sr.append(fullSearch);
sr.append("\" conditionGroup=\"");
sr.append(conditionGroup);
sr.append("\" tabindex=\"");
sr.append(tabindex);
sr.append("\" />");
executeMacro(writer, sr.toString());
ModelFormField.SubHyperlink subHyperlink = dropDownField.getSubHyperlink();
if (subHyperlink != null && subHyperlink.shouldUse(context)) {
makeHyperlinkString(writer, subHyperlink, context);
}
this.appendTooltip(writer, context, modelFormField);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class MacroFormRenderer method renderHiddenField.
public void renderHiddenField(Appendable writer, Map<String, Object> context, HiddenField hiddenField) throws IOException {
ModelFormField modelFormField = hiddenField.getModelFormField();
String value = hiddenField.getValue(context);
this.renderHiddenField(writer, context, modelFormField, value);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class MacroFormRenderer method renderTextField.
public void renderTextField(Appendable writer, Map<String, Object> context, TextField textField) throws IOException {
ModelFormField modelFormField = textField.getModelFormField();
String name = modelFormField.getParameterName(context);
String className = "";
String alert = "false";
String mask = "";
String placeholder = textField.getPlaceholder(context);
if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
className = modelFormField.getWidgetStyle();
if (modelFormField.shouldBeRed(context)) {
alert = "true";
}
}
String value = modelFormField.getEntry(context, textField.getDefaultValue(context));
String textSize = Integer.toString(textField.getSize());
String maxlength = "";
if (textField.getMaxlength() != null) {
maxlength = Integer.toString(textField.getMaxlength());
}
String event = modelFormField.getEvent();
String action = modelFormField.getAction(context);
String id = modelFormField.getCurrentContainerId(context);
String clientAutocomplete = "false";
// check for required field style on single forms
if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
String requiredStyle = modelFormField.getRequiredFieldStyle();
if (UtilValidate.isEmpty(requiredStyle)) {
requiredStyle = "required";
}
if (UtilValidate.isEmpty(className)) {
className = requiredStyle;
} else {
className = requiredStyle + " " + className;
}
}
List<ModelForm.UpdateArea> updateAreas = modelFormField.getOnChangeUpdateAreas();
boolean ajaxEnabled = updateAreas != null && this.javaScriptEnabled;
if (textField.getClientAutocompleteField() || ajaxEnabled) {
clientAutocomplete = "true";
}
if (UtilValidate.isNotEmpty(textField.getMask())) {
mask = textField.getMask();
}
String ajaxUrl = createAjaxParamsFromUpdateAreas(updateAreas, "", context);
boolean disabled = textField.getDisabled();
boolean readonly = textField.getReadonly();
String tabindex = modelFormField.getTabindex();
StringWriter sr = new StringWriter();
sr.append("<@renderTextField ");
sr.append("name=\"");
sr.append(name);
sr.append("\" className=\"");
sr.append(className);
sr.append("\" alert=\"");
sr.append(alert);
sr.append("\" value=\"");
sr.append(value);
sr.append("\" textSize=\"");
sr.append(textSize);
sr.append("\" maxlength=\"");
sr.append(maxlength);
sr.append("\" id=\"");
sr.append(id);
sr.append("\" event=\"");
if (event != null) {
sr.append(event);
}
sr.append("\" action=\"");
if (action != null) {
sr.append(action);
}
sr.append("\" disabled=");
sr.append(Boolean.toString(disabled));
sr.append(" readonly=");
sr.append(Boolean.toString(readonly));
sr.append(" clientAutocomplete=\"");
sr.append(clientAutocomplete);
sr.append("\" ajaxUrl=\"");
sr.append(ajaxUrl);
sr.append("\" ajaxEnabled=");
sr.append(Boolean.toString(ajaxEnabled));
sr.append(" mask=\"");
sr.append(mask);
sr.append("\" placeholder=\"");
sr.append(placeholder);
sr.append("\" tabindex=\"");
sr.append(tabindex);
sr.append("\" delegatorName=\"");
sr.append(((HttpSession) context.get("session")).getAttribute("delegatorName").toString());
sr.append("\" />");
executeMacro(writer, sr.toString());
ModelFormField.SubHyperlink subHyperlink = textField.getSubHyperlink();
if (subHyperlink != null && subHyperlink.shouldUse(context)) {
makeHyperlinkString(writer, subHyperlink, context);
}
this.addAsterisks(writer, context, modelFormField);
this.appendTooltip(writer, context, modelFormField);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class MacroFormRenderer method renderFormClose.
public void renderFormClose(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
String focusFieldName = modelForm.getFocusFieldName();
String formName = FormRenderer.getCurrentFormName(modelForm, context);
String containerId = FormRenderer.getCurrentContainerId(modelForm, context);
String hasRequiredField = "";
for (ModelFormField formField : modelForm.getFieldList()) {
if (formField.getRequiredField()) {
hasRequiredField = "Y";
break;
}
}
StringWriter sr = new StringWriter();
sr.append("<@renderFormClose ");
sr.append(" focusFieldName=\"");
sr.append(focusFieldName);
sr.append("\" formName=\"");
sr.append(formName);
sr.append("\" containerId=\"");
sr.append(containerId);
sr.append("\" hasRequiredField=\"");
sr.append(hasRequiredField);
sr.append("\" />");
executeMacro(writer, sr.toString());
if (modelForm instanceof ModelSingleForm) {
renderEndingBoundaryComment(writer, "Form Widget - Form Element", modelForm);
} else {
renderEndingBoundaryComment(writer, "Grid Widget - Grid Element", modelForm);
}
}
Aggregations