diff --git a/framework/widget/src/org/ofbiz/widget/form/FormRenderer.java b/framework/widget/src/org/ofbiz/widget/form/FormRenderer.java index e87d601e96..9f0fd37ca2 100644 --- a/framework/widget/src/org/ofbiz/widget/form/FormRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/form/FormRenderer.java @@ -89,12 +89,22 @@ public class FormRenderer { } } + public static String getFocusFieldName(ModelForm modelForm, Map context) { + String focusFieldName = (String) context.get(modelForm.getName().concat(".focusFieldName")); + if (focusFieldName == null) { + return ""; + } + return focusFieldName; + } + private final ModelForm modelForm; private final FormStringRenderer formStringRenderer; + private String focusFieldName; public FormRenderer(ModelForm modelForm, FormStringRenderer formStringRenderer) { this.modelForm = modelForm; this.formStringRenderer = formStringRenderer; + this.focusFieldName = modelForm.getFocusFieldName(); } private Collection> getFieldListsByPosition(List modelFormFieldList) { @@ -111,6 +121,10 @@ public class FormRenderer { return fieldsByPosition.values(); } + public String getFocusFieldName() { + return focusFieldName; + } + private List getHiddenIgnoredFields(Map context, Set alreadyRendered, List fieldList, int position) { /* @@ -1093,6 +1107,15 @@ public class FormRenderer { continue; } alreadyRendered.add(currentFormField.getName()); + if (focusFieldName.isEmpty()) { + if (fieldInfo.getFieldType() != FieldInfo.DISPLAY && fieldInfo.getFieldType() != FieldInfo.HIDDEN + && fieldInfo.getFieldType() != FieldInfo.DISPLAY_ENTITY + && fieldInfo.getFieldType() != FieldInfo.IGNORED + && fieldInfo.getFieldType() != FieldInfo.IMAGE) { + focusFieldName = currentFormField.getName(); + context.put(modelForm.getName().concat(".focusFieldName"), focusFieldName); + } + } boolean stayingOnRow = false; if (lastFormField != null) { diff --git a/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java b/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java index 3ef4e122c2..376b94b456 100644 --- a/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java @@ -1347,7 +1347,7 @@ public final class MacroFormRenderer implements FormStringRenderer { } public void renderFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - String focusFieldName = modelForm.getfocusFieldName(); + String focusFieldName = FormRenderer.getFocusFieldName(modelForm, context); String formName = FormRenderer.getCurrentFormName(modelForm, context); String containerId = FormRenderer.getCurrentContainerId(modelForm, context); String hasRequiredField = ""; diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java b/framework/widget/src/org/ofbiz/widget/form/ModelForm.java index 9800570201..eda200fdb1 100644 --- a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java +++ b/framework/widget/src/org/ofbiz/widget/form/ModelForm.java @@ -730,12 +730,8 @@ public class ModelForm extends ModelWidget { sortOrderFields.trimToSize(); this.sortOrderFields = Collections.unmodifiableList(sortOrderFields); String focusFieldName = formElement.getAttribute("focus-field-name"); - if (focusFieldName.isEmpty()) { - if (parentModelForm != null) { - focusFieldName = parentModelForm.focusFieldName; - } else { - // TODO: Set this automatically if not specified - } + if (focusFieldName.isEmpty() && parentModelForm != null) { + focusFieldName = parentModelForm.focusFieldName; } this.focusFieldName = focusFieldName; } @@ -1006,10 +1002,6 @@ public class ModelForm extends ModelWidget { return fieldList; } - public String getfocusFieldName() { - return this.focusFieldName; - } - public String getFocusFieldName() { return focusFieldName; } diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java b/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java index fd6435ec8a..ad22cedf33 100644 --- a/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java @@ -1223,7 +1223,7 @@ public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRe */ public void renderFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { writer.append(""); - String focusFieldName = modelForm.getfocusFieldName(); + String focusFieldName = FormRenderer.getFocusFieldName(modelForm, context); if (UtilValidate.isNotEmpty(focusFieldName)) { appendWhitespace(writer); writer.append("