diff --git a/framework/common/webcommon/includes/ajaxAutocompleteOptions.ftl b/framework/common/webcommon/includes/ajaxAutocompleteOptions.ftl index 4f34285afe..acb7060d46 100644 --- a/framework/common/webcommon/includes/ajaxAutocompleteOptions.ftl +++ b/framework/common/webcommon/includes/ajaxAutocompleteOptions.ftl @@ -17,9 +17,11 @@ specific language governing permissions and limitations under the License. --> - \ No newline at end of file +<#if autocompleteOptions?exists> + + diff --git a/framework/example/webapp/example/WEB-INF/actions/includes/findExampleFeatures.bsh b/framework/example/webapp/example/WEB-INF/actions/includes/findExampleFeatures.bsh index 502c23a106..c3d5e48fbe 100644 --- a/framework/example/webapp/example/WEB-INF/actions/includes/findExampleFeatures.bsh +++ b/framework/example/webapp/example/WEB-INF/actions/includes/findExampleFeatures.bsh @@ -19,6 +19,7 @@ import java.util.TreeSet; import javolution.util.FastList; +import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityFieldValue; diff --git a/framework/example/widget/example/ExampleForms.xml b/framework/example/widget/example/ExampleForms.xml index a5e7041d72..d2d27e89e1 100644 --- a/framework/example/widget/example/ExampleForms.xml +++ b/framework/example/widget/example/ExampleForms.xml @@ -173,7 +173,10 @@ under the License.
- + + + + diff --git a/framework/images/webapp/images/selectall.js b/framework/images/webapp/images/selectall.js index 8acd1c1043..3eb4f564fb 100644 --- a/framework/images/webapp/images/selectall.js +++ b/framework/images/webapp/images/selectall.js @@ -286,10 +286,18 @@ function ajaxSubmitFormUpdateAreas(form, areaCsvString) { ajaxSubmitRequestUpdateAreas(form.action, form.serialize(true), areaCsvString); } -function ajaxAutoCompleter(textFieldId,url,params) { - var optionsDivId = textFieldId + "_autoCompleterOptions"; - $(textFieldId ).insert({after: '
'}); - new Ajax.Autocompleter($(textFieldId), optionsDivId, url, {parameters: params}); +/** Enable auto-completion for text elements. + * @param areaCsvString The area CSV string. The CSV string is a flat array in the + * form of: areaId, target, target parameters [, areaId, target, target parameters...]. +*/ +function ajaxAutoCompleter(areaCsvString) { + var areaArray = areaCsvString.split(","); + var numAreas = parseInt(areaArray.length / 3); + for (var i = 0; i < numAreas * 3; i = i + 3) { + var optionsDivId = areaArray[i] + "_autoCompleterOptions"; + $(areaArray[i]).insert({after: '
'}); + new Ajax.Autocompleter($(areaArray[i]), optionsDivId, areaArray[i + 1], {parameters: areaArray[i + 2]}); + } } // ===== End of Ajax Functions ===== // diff --git a/framework/widget/dtd/widget-form.xsd b/framework/widget/dtd/widget-form.xsd index 146ebf10cf..5e8799863f 100644 --- a/framework/widget/dtd/widget-form.xsd +++ b/framework/widget/dtd/widget-form.xsd @@ -865,10 +865,6 @@ under the License. - - - Url to request user options. - diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java b/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java index 5f1aa56b84..c1e698f66d 100644 --- a/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java +++ b/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java @@ -37,10 +37,10 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.ObjectType; import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilFormatOut; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.UtilFormatOut; import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.base.util.collections.MapStack; import org.ofbiz.base.util.string.FlexibleStringExpander; @@ -58,9 +58,9 @@ import org.ofbiz.entity.model.ModelReader; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; -import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ModelParam; import org.ofbiz.service.ModelService; +import org.ofbiz.widget.form.ModelForm.UpdateArea; import org.w3c.dom.Element; import bsh.EvalError; @@ -104,6 +104,11 @@ public class ModelFormField { protected String headerLink; protected String headerLinkStyle; + /** On Change Event areas to be updated. */ + protected List onChangeUpdateAreas; + /** On Click Event areas to be updated. */ + protected List onClickUpdateAreas; + // ===== CONSTRUCTORS ===== /** Default Constructor */ public ModelFormField(ModelForm modelForm) { @@ -155,8 +160,8 @@ public class ModelFormField { } // get sub-element and set fieldInfo - Element subElement = UtilXml.firstChildElement(fieldElement); - if (subElement != null) { + List subElements = UtilXml.childElementList(fieldElement); + for (Element subElement : subElements) { String subElementName = subElement.getTagName(); if (Debug.verboseOn()) Debug.logVerbose("Processing field " + this.name + " with type info tag " + subElementName, module); @@ -204,12 +209,39 @@ public class ModelFormField { this.fieldInfo = new PasswordField(subElement, this); } else if ("image".equals(subElementName)) { this.fieldInfo = new ImageField(subElement, this); + } else if ("on-field-event-update-area".equals(subElementName)) { + addOnEventUpdateArea(new UpdateArea(subElement)); } else { throw new IllegalArgumentException("The field sub-element with name " + subElementName + " is not supported"); } } } + public void addOnEventUpdateArea(UpdateArea updateArea) { + // Event types are sorted as a convenience for the rendering classes + Debug.logInfo(this.modelForm.getName() + ":" + this.name + " adding UpdateArea type " + updateArea.getEventType(), module); + if ("change".equals(updateArea.getEventType())) { + addOnChangeUpdateArea(updateArea); + } else if ("click".equals(updateArea.getEventType())) { + addOnClickUpdateArea(updateArea); + } + } + + protected void addOnChangeUpdateArea(UpdateArea updateArea) { + if (onChangeUpdateAreas == null) { + onChangeUpdateAreas = FastList.newInstance(); + } + onChangeUpdateAreas.add(updateArea); + Debug.logInfo(this.modelForm.getName() + ":" + this.name + " onChangeUpdateAreas size = " + onChangeUpdateAreas.size(), module); + } + + protected void addOnClickUpdateArea(UpdateArea updateArea) { + if (onClickUpdateAreas == null) { + onClickUpdateAreas = FastList.newInstance(); + } + onClickUpdateAreas.add(updateArea); + } + public void mergeOverrideModelFormField(ModelFormField overrideFormField) { if (overrideFormField == null) return; @@ -263,8 +295,15 @@ public class ModelFormField { if (overrideFormField.fieldInfo != null) { this.setHeaderLink(overrideFormField.headerLink); } - if (UtilValidate.isNotEmpty(overrideFormField.idName)) + if (UtilValidate.isNotEmpty(overrideFormField.idName)) { this.idName = overrideFormField.idName; + } + if (overrideFormField.onChangeUpdateAreas != null) { + this.onChangeUpdateAreas = overrideFormField.onChangeUpdateAreas; + } + if (overrideFormField.onClickUpdateAreas != null) { + this.onClickUpdateAreas = overrideFormField.onClickUpdateAreas; + } } public boolean induceFieldInfo(String defaultFieldType) { @@ -541,6 +580,14 @@ public class ModelFormField { this.fieldInfo.renderFieldString(buffer, context, formStringRenderer); } + public List getOnChangeUpdateAreas() { + return onChangeUpdateAreas; + } + + public List getOnClickUpdateAreas() { + return onClickUpdateAreas; + } + /** * @return */ @@ -2167,8 +2214,6 @@ public class ModelFormField { protected SubHyperlink subHyperlink; protected boolean disabled; protected boolean clientAutocompleteField; - protected FlexibleStringExpander serverAutocompleteTargetExdr; - protected FlexibleStringExpander serverAutocompleteParamsExdr; protected TextField() { super(); @@ -2213,9 +2258,6 @@ public class ModelFormField { if (subHyperlinkElement != null) { this.subHyperlink = new SubHyperlink(subHyperlinkElement); } - this.serverAutocompleteTargetExdr = new FlexibleStringExpander(element.getAttribute("server-autocomplete-target")); - this.serverAutocompleteParamsExdr = new FlexibleStringExpander(element.getAttribute("server-autocomplete-params")); - } public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { @@ -2293,21 +2335,6 @@ public class ModelFormField { public void setSubHyperlink(SubHyperlink newSubHyperlink) { this.subHyperlink = newSubHyperlink; } - public String getServerAutocompleteTarget(Map context) { - if(serverAutocompleteTargetExdr !=null){ - return this.serverAutocompleteTargetExdr.expandString(context); - } else { - return ""; - } - } - public String getServerAutocompleteParams(Map context) { - if(serverAutocompleteParamsExdr !=null){ - return this.serverAutocompleteParamsExdr.expandString(context); - } else { - return ""; - } - } - } public static class TextareaField extends FieldInfo { diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java b/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java index ff2be03de8..9f3f570e17 100644 --- a/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java @@ -72,16 +72,21 @@ public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRe public static final String module = HtmlFormRenderer.class.getName(); - HttpServletRequest request; - HttpServletResponse response; + protected HttpServletRequest request; + protected HttpServletResponse response; + protected RequestHandler rh; protected String lastFieldGroupId = ""; protected boolean renderPagination = true; + protected boolean javaScriptEnabled = false; protected HtmlFormRenderer() {} public HtmlFormRenderer(HttpServletRequest request, HttpServletResponse response) { this.request = request; this.response = response; + ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); + this.rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); + this.javaScriptEnabled = UtilHttp.isJavaScriptEnabled(request); } public boolean getRenderPagination() { @@ -93,10 +98,7 @@ public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRe } public void appendOfbizUrl(StringBuffer buffer, String location) { - ServletContext ctx = (ServletContext) this.request.getAttribute("servletContext"); - RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - // make and append the link - buffer.append(rh.makeLink(this.request, this.response, location)); + buffer.append(this.rh.makeLink(this.request, this.response, location)); } public void appendContentUrl(StringBuffer buffer, String location) { @@ -279,7 +281,9 @@ public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRe buffer.append('"'); } - if (!textField.getClientAutocompleteField()) { + List updateAreas = modelFormField.getOnChangeUpdateAreas(); + boolean ajaxEnabled = updateAreas != null && this.javaScriptEnabled; + if (!textField.getClientAutocompleteField() || ajaxEnabled) { buffer.append(" autocomplete=\"off\""); } @@ -290,18 +294,12 @@ public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRe this.makeHyperlinkString(buffer, textField.getSubHyperlink(), context); this.appendTooltip(buffer, context, modelFormField); - //Add javascript block to execute a function that will register textfield to autocompleter Ajax system. - String serverAutocompleteTarget = textField.getServerAutocompleteTarget(context); - if (UtilValidate.isNotEmpty(serverAutocompleteTarget)) { + + if (ajaxEnabled) { appendWhitespace(buffer); buffer.append(""); } @@ -899,7 +897,7 @@ public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRe updateAreas.add(new ModelForm.UpdateArea("submit", formId, backgroundSubmitRefreshTarget)); } - boolean ajaxEnabled = (updateAreas != null || UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) && UtilHttp.isJavaScriptEnabled(request); + boolean ajaxEnabled = (updateAreas != null || UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) && this.javaScriptEnabled; if (ajaxEnabled) { buffer.append(" updateAreas = modelForm.getOnPaginateUpdateAreas(); String targetService = modelForm.getPaginateTarget(context); - if (javaScriptEnabled) { + if (this.javaScriptEnabled) { if (UtilValidate.isNotEmpty(updateAreas)) { ajaxEnabled = true; } @@ -2087,8 +2060,6 @@ public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRe if (viewSizeParam.equals("viewSize")) viewSizeParam = "VIEW_SIZE"; String str = (String) context.get("_QBESTRING_"); - ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); - RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); // strip legacy viewIndex/viewSize params from the query string String queryString = UtilHttp.stripViewParamsFromQueryString(str); @@ -2129,6 +2100,7 @@ public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRe appendWhitespace(buffer); buffer.append("