You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Anil Patel <an...@hotwaxmedia.com> on 2008/06/06 19:38:40 UTC

Re: svn commit: r661450 - in /ofbiz/trunk/framework: common/webcommon/includes/ example/webapp/example/WEB-INF/actions/includes/ example/widget/example/ images/webapp/images/ widget/dtd/ widget/src/org/ofbiz/widget/form/ widget/src/org/ofbiz/widget/html/

Adrian,
This commit along with svn #661345 is a great enhancement. I have a  
feeling that its too generic. Like name of Sub element  "on-field- 
event-update-area" kind of tells me that on certain event, certain  
area of screen will be updated. Like I select country code and list of  
states will be updated, Something that can be otherwise called   
"Partial Form Refresh (submission)". There can be various ways of this  
generic element.

The way its implemented in this commit is very specialized use. On  
change in textbox a dropdown appears and user can navigate in that  
list and select a option. This is a clearly a very specialized  
handling of form event and expected user Interaction. Unless somebody  
looks at the implementation code its hard figure out.

I think we should add a sub element <use-server-autocomplete> and this  
element can have attributes and sub elements that we may need to pass  
to the Ajax.Autocompleter control of Script.Aculo.us.

And for <on-field-event-update-area> element we should be able to pass  
in  name of event handler function name. Developer can use such event  
listeners to implement custom stuff.

Please ask questions if I am not clear enough. I'll like to clear this  
asap because this is holding me up with my current project.

Thanks and Regards
Anil Patel





On May 29, 2008, at 3:48 PM, adrianc@apache.org wrote:

> Author: adrianc
> Date: Thu May 29 12:48:24 2008
> New Revision: 661450
>
> URL: http://svn.apache.org/viewvc?rev=661450&view=rev
> Log:
> Form widget Ajax refinements.
>
> Changed attribute-based ajax calls to on-event-update-area elements.  
> Fixed bug in autocomplete. Cleaned up some of the rendering code.
>
> Modified:
>    ofbiz/trunk/framework/common/webcommon/includes/ 
> ajaxAutocompleteOptions.ftl
>    ofbiz/trunk/framework/example/webapp/example/WEB-INF/actions/ 
> includes/findExampleFeatures.bsh
>    ofbiz/trunk/framework/example/widget/example/ExampleForms.xml
>    ofbiz/trunk/framework/images/webapp/images/selectall.js
>    ofbiz/trunk/framework/widget/dtd/widget-form.xsd
>    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ 
> ModelFormField.java
>    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlFormRenderer.java
>    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlWidgetRenderer.java
>
> Modified: ofbiz/trunk/framework/common/webcommon/includes/ 
> ajaxAutocompleteOptions.ftl
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/webcommon/includes/ajaxAutocompleteOptions.ftl?rev=661450&r1=661449&r2=661450&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/common/webcommon/includes/ 
> ajaxAutocompleteOptions.ftl (original)
> +++ ofbiz/trunk/framework/common/webcommon/includes/ 
> ajaxAutocompleteOptions.ftl Thu May 29 12:48:24 2008
> @@ -17,9 +17,11 @@
> under the License.
> -->
>
> -<ul>
> -  <#list autocompleteOptions as autocompleteOption>
> -  	<#assign fields = autocompleteOption.values()/>
> -    <li><#list fields as field><#if field_index == 1><span  
> class="informal"> </#if>${field}<#if (field_index > 0)><#if  
> field_has_next> <#else></span></#if></#if></#list></li>
> -  </#list>
> -</ul>
> \ No newline at end of file
> +<#if autocompleteOptions?exists>
> +  <ul>
> +    <#list autocompleteOptions as autocompleteOption>
> +  	  <#assign fields = autocompleteOption.values()/>
> +      <li><#list fields as field><#if field_index == 1><span  
> class="informal"> </#if>${field}<#if (field_index > 0)><#if  
> field_has_next> <#else></span></#if></#if></#list></li>
> +    </#list>
> +  </ul>
> +</#if>
>
> Modified: ofbiz/trunk/framework/example/webapp/example/WEB-INF/ 
> actions/includes/findExampleFeatures.bsh
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/webapp/example/WEB-INF/actions/includes/findExampleFeatures.bsh?rev=661450&r1=661449&r2=661450&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/example/webapp/example/WEB-INF/actions/ 
> includes/findExampleFeatures.bsh (original)
> +++ ofbiz/trunk/framework/example/webapp/example/WEB-INF/actions/ 
> includes/findExampleFeatures.bsh Thu May 29 12:48:24 2008
> @@ -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;
>
> Modified: ofbiz/trunk/framework/example/widget/example/ 
> ExampleForms.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/ExampleForms.xml?rev=661450&r1=661449&r2=661450&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/example/widget/example/ExampleForms.xml  
> (original)
> +++ ofbiz/trunk/framework/example/widget/example/ExampleForms.xml  
> Thu May 29 12:48:24 2008
> @@ -173,7 +173,10 @@
>     <form name="AddExampleFeatureAppl" type="single"  
> target="example_createExampleFeatureAppl" title="">
>         <auto-fields-service service-name="createExampleFeatureAppl"/>
>         <field name="exampleId"><hidden/></field>
> -        <field name="exampleFeatureId" id- 
> name="exampleFeatureId"><text server-autocomplete- 
> target="findExampleFeatures"></text></field>
> +        <field name="exampleFeatureId" id-name="exampleFeatureId">
> +            <text/>
> +            <on-field-event-update-area event-type="change" area- 
> id="exampleFeatureId" area-target="findExampleFeatures"/>
> +        </field>
>         <!-- <field name="exampleFeatureId" title="$ 
> {uiLabelMap.ExampleFeature}" id-name="exampleFeatureId"><lookup  
> target-form-name="LookupExampleFeature"/></field> -->
>         <field name="exampleFeatureApplTypeId" title="$ 
> {uiLabelMap.CommonType}">
>             <drop-down allow-empty="false">
>
> Modified: ofbiz/trunk/framework/images/webapp/images/selectall.js
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/selectall.js?rev=661450&r1=661449&r2=661450&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/images/webapp/images/selectall.js (original)
> +++ ofbiz/trunk/framework/images/webapp/images/selectall.js Thu May  
> 29 12:48:24 2008
> @@ -286,10 +286,18 @@
>     ajaxSubmitRequestUpdateAreas(form.action, form.serialize(true),  
> areaCsvString);
> }
>
> -function ajaxAutoCompleter(textFieldId,url,params) {
> -	var optionsDivId = textFieldId + "_autoCompleterOptions";
> -	$(textFieldId ).insert({after: '<div class="autocomplete"' + 'id='  
> + optionsDivId + '></div>'});
> -    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: '<div class="autocomplete"' +  
> 'id=' + optionsDivId + '></div>'});
> +        new Ajax.Autocompleter($(areaArray[i]), optionsDivId,  
> areaArray[i + 1], {parameters: areaArray[i + 2]});	
> +    }
> }
> // ===== End of Ajax Functions ===== //
>
>
> Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=661450&r1=661449&r2=661450&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
> +++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Thu May 29  
> 12:48:24 2008
> @@ -865,10 +865,6 @@
>                 </xs:restriction>
>             </xs:simpleType>
>         </xs:attribute>
> -        <xs:attribute type="xs:string" name="server-autocomplete- 
> params"/>
> -        <xs:attribute type="xs:string" name="server-autocomplete- 
> target">
> -            <xs:annotation><xs:documentation>Url to request user  
> options.</xs:documentation></xs:annotation>
> -        </xs:attribute>
>     </xs:attributeGroup>
>     <xs:element name="textarea" substitutionGroup="AllFields">
>         <xs:complexType>
>
> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ 
> ModelFormField.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=661450&r1=661449&r2=661450&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ 
> ModelFormField.java (original)
> +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ 
> ModelFormField.java Thu May 29 12:48:24 2008
> @@ -37,10 +37,10 @@
> 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.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 @@
>     protected String headerLink;
>     protected String headerLinkStyle;
>
> +    /** On Change Event areas to be updated. */
> +    protected List<UpdateArea> onChangeUpdateAreas;
> +    /** On Click Event areas to be updated. */
> +    protected List<UpdateArea> onClickUpdateAreas;
> +
>     // ===== CONSTRUCTORS =====
>     /** Default Constructor */
>     public ModelFormField(ModelForm modelForm) {
> @@ -155,8 +160,8 @@
>         }
>
>         // get sub-element and set fieldInfo
> -        Element subElement = UtilXml.firstChildElement(fieldElement);
> -        if (subElement != null) {
> +        List<? extends Element> 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 @@
>                 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 @@
>         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 @@
>         this.fieldInfo.renderFieldString(buffer, context,  
> formStringRenderer);
>     }
>
> +    public List<UpdateArea> getOnChangeUpdateAreas() {
> +        return onChangeUpdateAreas;
> +    }
> +
> +    public List<UpdateArea> getOnClickUpdateAreas() {
> +        return onClickUpdateAreas;
> +    }
> +
>     /**
>      * @return
>      */
> @@ -2167,8 +2214,6 @@
>         protected SubHyperlink subHyperlink;
>         protected boolean disabled;
>         protected boolean clientAutocompleteField;
> -        protected FlexibleStringExpander  
> serverAutocompleteTargetExdr;
> -        protected FlexibleStringExpander  
> serverAutocompleteParamsExdr;
>
>         protected TextField() {
>             super();
> @@ -2213,9 +2258,6 @@
>             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 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 {
>
> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlFormRenderer.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?rev=661450&r1=661449&r2=661450&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlFormRenderer.java (original)
> +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlFormRenderer.java Thu May 29 12:48:24 2008
> @@ -72,16 +72,21 @@
>
>     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 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 @@
>             buffer.append('"');
>         }
>
> -        if (!textField.getClientAutocompleteField()) {
> +        List<ModelForm.UpdateArea> updateAreas =  
> modelFormField.getOnChangeUpdateAreas();
> +        boolean ajaxEnabled = updateAreas != null &&  
> this.javaScriptEnabled;
> +        if (!textField.getClientAutocompleteField() || ajaxEnabled) {
>             buffer.append(" autocomplete=\"off\"");
>         }
>
> @@ -290,18 +294,12 @@
>         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("<script language=\"JavaScript\" type= 
> \"text/javascript\">");
>             appendWhitespace(buffer);
> -            buffer.append("ajaxAutoCompleter('");
> -            buffer.append(idName);
> -            buffer.append("', '");
> -            WidgetWorker.buildHyperlinkUrl(buffer,  
> serverAutocompleteTarget,HyperlinkField.DEFAULT_TARGET_TYPE,  
> request, response, context);
> -            buffer.append("', '");
> -             
> buffer.append(textField.getServerAutocompleteParams(context) + "');");
> +            buffer.append("ajaxAutoCompleter('" +  
> createAjaxParamsFromUpdateAreas(updateAreas, null, context) + "');");
>             appendWhitespace(buffer);
>             buffer.append("</script>");
>         }
> @@ -899,7 +897,7 @@
>                 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("<input type=\"button\"");
>             } else {
> @@ -935,33 +933,9 @@
>
>             if (ajaxEnabled) {
>                 buffer.append(" onclick=\"");
> -                if (updateAreas.size() == 1) {
> -                    ModelForm.UpdateArea updateArea =  
> updateAreas.get(0);
> -                    buffer.append("submitFormInBackground($('");
> -                    buffer.append(formId);
> -                    buffer.append("'), '");
> -                    buffer.append(updateArea.getAreaId());
> -                    buffer.append("', '");
> -                    this.appendOfbizUrl(buffer,  
> updateArea.getAreaTarget(context));
> -                } else {
> -                    buffer.append("ajaxSubmitFormUpdateAreas($('");
> -                    buffer.append(formId);
> -                    buffer.append("'), '");
> -                    boolean firstLoop = true;
> -                    for (ModelForm.UpdateArea updateArea :  
> updateAreas) {
> -                        if (firstLoop) {
> -                            firstLoop = false;
> -                        } else {
> -                            buffer.append(",");
> -                        }
> -                        String targetString =  
> updateArea.getAreaTarget(context);
> -                        String target =  
> UtilHttp.removeQueryStringFromTarget(targetString);
> -                        String targetParams =  
> UtilHttp.getQueryStringFromTarget(targetString);
> -                        targetParams = targetParams.replace("?", "");
> -                        targetParams =  
> targetParams.replace("&amp;", "&");
> -                        buffer.append(updateArea.getAreaId() + ","  
> + target + "," + targetParams);
> -                    }
> -                }
> +                buffer.append("ajaxSubmitFormUpdateAreas($('");
> +                buffer.append(formId);
> +                buffer.append("'), '" +  
> createAjaxParamsFromUpdateAreas(updateAreas, null, context));
>                 buffer.append("')\"");
>             }
>
> @@ -2036,11 +2010,10 @@
>     }
>
>     public void renderNextPrev(StringBuffer buffer, Map context,  
> ModelForm modelForm) {
> -        boolean javaScriptEnabled =  
> UtilHttp.isJavaScriptEnabled(request);
>         boolean ajaxEnabled = false;
>         List<ModelForm.UpdateArea> updateAreas =  
> modelForm.getOnPaginateUpdateAreas();
>         String targetService = modelForm.getPaginateTarget(context);
> -        if (javaScriptEnabled) {
> +        if (this.javaScriptEnabled) {
>             if (UtilValidate.isNotEmpty(updateAreas)) {
>                 ajaxEnabled = true;
>             }
> @@ -2087,8 +2060,6 @@
>         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 @@
>         appendWhitespace(buffer);
>         buffer.append(" <ul>");
>         appendWhitespace(buffer);
> +
>         String linkText;
>
>         // First button
> @@ -2136,23 +2108,7 @@
>         if (viewIndex > 0) {
>             buffer.append("\"><a href=\"");
>             if (ajaxEnabled) {
> -                buffer.append("javascript:ajaxUpdateAreas('");
> -                for (ModelForm.UpdateArea updateArea : updateAreas) {
> -                    linkText =   
> UtilHttp.getQueryStringFromTarget(updateArea.getAreaTarget(context));
> -                    if (UtilValidate.isEmpty(linkText)) {
> -                        linkText = "";
> -                    }
> -                    if (!UtilValidate.isEmpty(queryString) && ! 
> queryString.equals("null")) {
> -                        linkText += queryString + "&";
> -                    }
> -                    linkText += viewSizeParam + "=" + viewSize +  
> "&" + viewIndexParam + "=" + 0 + anchor;
> -                    linkText = linkText.replace("?", "");
> -                    linkText = linkText.replace("&amp;", "&");
> -                    buffer.append(updateArea.getAreaId() + ",");
> -                    buffer.append(rh.makeLink(this.request,  
> this.response,  
> UtilHttp 
> .removeQueryStringFromTarget(updateArea.getAreaTarget(context))));
> -                    buffer.append("," + linkText + ",");
> -                }
> -                buffer.append("')");
> +                buffer.append("javascript:ajaxUpdateAreas('" +  
> createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText + 0 +  
> anchor, context) + "')");
>             } else {
>                 linkText = prepLinkText + 0 + anchor;
>                 buffer.append(rh.makeLink(this.request,  
> this.response, urlPath + linkText));
> @@ -2170,23 +2126,7 @@
>         if (viewIndex > 0) {
>             buffer.append("\"><a href=\"");
>             if (ajaxEnabled) {
> -                buffer.append("javascript:ajaxUpdateAreas('");
> -                for (ModelForm.UpdateArea updateArea : updateAreas) {
> -                    linkText =  
> UtilHttp.getQueryStringFromTarget(updateArea.getAreaTarget(context));
> -                    if (UtilValidate.isEmpty(linkText)) {
> -                        linkText = "";
> -                    }
> -                    if (!UtilValidate.isEmpty(queryString) && ! 
> queryString.equals("null")) {
> -                        linkText += queryString + "&";
> -                    }
> -                    linkText += viewSizeParam + "=" + viewSize +  
> "&" + viewIndexParam + "=" + (viewIndex - 1) + anchor;
> -                    linkText = linkText.replace("?", "");
> -                    linkText = linkText.replace("&amp;", "&");
> -                    buffer.append(updateArea.getAreaId() + ",");
> -                    buffer.append(rh.makeLink(this.request,  
> this.response,  
> UtilHttp 
> .removeQueryStringFromTarget(updateArea.getAreaTarget(context))));
> -                    buffer.append("," + linkText + ",");
> -                }
> -                buffer.append("')");
> +                buffer.append("javascript:ajaxUpdateAreas('" +  
> createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText +  
> (viewIndex - 1) + anchor, context) + "')");
>             } else {
>                 linkText = prepLinkText + (viewIndex - 1) + anchor;
>                 buffer.append(rh.makeLink(this.request,  
> this.response, urlPath + linkText));
> @@ -2200,34 +2140,18 @@
>         appendWhitespace(buffer);
>
>         // Page select dropdown
> -        if (listSize > 0 && javaScriptEnabled) {
> +        if (listSize > 0 && this.javaScriptEnabled) {
>             buffer.append("  <li>").append(pageLabel).append("  
> <select name=\"page\" size=\"1\" onchange=\"");
>             if (ajaxEnabled) {
> -                buffer.append("javascript:ajaxUpdateAreas('");
> -                for (ModelForm.UpdateArea updateArea : updateAreas) {
> -                    linkText =  
> UtilHttp.getQueryStringFromTarget(updateArea.getAreaTarget(context));
> -                    if (UtilValidate.isEmpty(linkText)) {
> -                        linkText = "";
> -                    }
> -                    if (!UtilValidate.isEmpty(queryString) && ! 
> queryString.equals("null")) {
> -                        linkText += queryString + "&";
> -                    }
> -                    linkText += viewSizeParam + "=" + viewSize +  
> "&" + viewIndexParam + "=' + this.value + '";
> -                    linkText = linkText.replace("?", "");
> -                    linkText = linkText.replace("&amp;", "&");
> -                    buffer.append(updateArea.getAreaId() + ",");
> -                    buffer.append(rh.makeLink(this.request,  
> this.response,  
> UtilHttp 
> .removeQueryStringFromTarget(updateArea.getAreaTarget(context))));
> -                    buffer.append("," + linkText + ",");
> -                }
> -                buffer.append("')\"");
> +                buffer.append("javascript:ajaxUpdateAreas('" +  
> createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText + "' +  
> this.value", context) + ")");
>             } else {
>                 linkText = prepLinkText;
>                 if (linkText.startsWith("/")) {
>                     linkText = linkText.substring(1);
>                 }
> -                buffer.append("location.href = '" + urlPath +  
> linkText + "' + this.value;\"");
> +                buffer.append("location.href = '" + urlPath +  
> linkText + "' + this.value;");
>             }
> -            buffer.append(">");
> +            buffer.append("\">");
>             // actual value
>             int page = 0;
>             for (int i = 0; i < listSize;) {
> @@ -2256,23 +2180,7 @@
>         if (highIndex < listSize) {
>             buffer.append("\"><a href=\"");
>             if (ajaxEnabled) {
> -                buffer.append("javascript:ajaxUpdateAreas('");
> -                for (ModelForm.UpdateArea updateArea : updateAreas) {
> -                    linkText =  
> UtilHttp.getQueryStringFromTarget(updateArea.getAreaTarget(context));
> -                    if (UtilValidate.isEmpty(linkText)) {
> -                        linkText = "";
> -                    }
> -                    if (!UtilValidate.isEmpty(queryString) && ! 
> queryString.equals("null")) {
> -                        linkText += queryString + "&";
> -                    }
> -                    linkText += viewSizeParam + "=" + viewSize +  
> "&" + viewIndexParam + "=" + (viewIndex + 1) + anchor;
> -                    linkText = linkText.replace("?", "");
> -                    linkText = linkText.replace("&amp;", "&");
> -                    buffer.append(updateArea.getAreaId() + ",");
> -                    buffer.append(rh.makeLink(this.request,  
> this.response,  
> UtilHttp 
> .removeQueryStringFromTarget(updateArea.getAreaTarget(context))));
> -                    buffer.append("," + linkText + ",");
> -                }
> -                buffer.append("')");
> +                buffer.append("javascript:ajaxUpdateAreas('" +  
> createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText +  
> (viewIndex + 1) + anchor, context) + "')");
>             } else {
>                 linkText = prepLinkText + (viewIndex + 1) + anchor;
>                 buffer.append(rh.makeLink(this.request,  
> this.response, urlPath + linkText));
> @@ -2290,23 +2198,7 @@
>         if (highIndex < listSize) {
>             buffer.append("\"><a href=\"");
>             if (ajaxEnabled) {
> -                buffer.append("javascript:ajaxUpdateAreas('");
> -                for (ModelForm.UpdateArea updateArea : updateAreas) {
> -                    linkText =  
> UtilHttp.getQueryStringFromTarget(updateArea.getAreaTarget(context));
> -                    if (UtilValidate.isEmpty(linkText)) {
> -                        linkText = "";
> -                    }
> -                    if (!UtilValidate.isEmpty(queryString) && ! 
> queryString.equals("null")) {
> -                        linkText += queryString + "&";
> -                    }
> -                    linkText += viewSizeParam + "=" + viewSize +  
> "&" + viewIndexParam + "=" + (listSize / viewSize) + anchor;
> -                    linkText = linkText.replace("?", "");
> -                    linkText = linkText.replace("&amp;", "&");
> -                    buffer.append(updateArea.getAreaId() + ",");
> -                    buffer.append(rh.makeLink(this.request,  
> this.response,  
> UtilHttp 
> .removeQueryStringFromTarget(updateArea.getAreaTarget(context))));
> -                    buffer.append("," + linkText + ",");
> -                }
> -                buffer.append("')");
> +                buffer.append("javascript:ajaxUpdateAreas('" +  
> createAjaxParamsFromUpdateAreas(updateAreas, prepLinkText +  
> (listSize / viewSize) + anchor, context) + "')");
>             } else {
>                 linkText = prepLinkText + (listSize / viewSize) +  
> anchor;
>                 buffer.append(rh.makeLink(this.request,  
> this.response, urlPath + linkText));
> @@ -2585,4 +2477,38 @@
>              buffer.append(titleText);
>         }
>     }
> +
> +    /** Create an ajaxXxxx JavaScript CSV string from a list of  
> UpdateArea objects. See
> +     * <code>selectall.js</code>.
> +     * @param updateAreas
> +     * @param extraParams Renderer-supplied additional target  
> parameters
> +     * @param context
> +     * @return Parameter string or empty string if no UpdateArea  
> objects were found
> +     */
> +    public String  
> createAjaxParamsFromUpdateAreas(List<ModelForm.UpdateArea>  
> updateAreas, String extraParams, Map<String, ? extends Object>  
> context) {
> +        if (updateAreas == null) {
> +            return "";
> +        }
> +        String ajaxUrl = "";
> +        boolean firstLoop = true;
> +        for (ModelForm.UpdateArea updateArea : updateAreas) {
> +            if (firstLoop) {
> +                firstLoop = false;
> +            } else {
> +                ajaxUrl += ",";
> +            }
> +            String targetUrl = updateArea.getAreaTarget(context);
> +            String ajaxParams = getAjaxParamsFromTarget(targetUrl);
> +            if (UtilValidate.isNotEmpty(extraParams)) {
> +                if (ajaxParams.length() > 0 && ! 
> extraParams.startsWith("&")) {
> +                    ajaxParams += "&";
> +                }
> +                ajaxParams += extraParams;
> +            }
> +            ajaxUrl += updateArea.getAreaId() + ",";
> +            ajaxUrl += this.rh.makeLink(this.request,  
> this.response, UtilHttp.removeQueryStringFromTarget(targetUrl));
> +            ajaxUrl += "," + ajaxParams;
> +        }
> +        return ajaxUrl;
> +    }
> }
>
> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlWidgetRenderer.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlWidgetRenderer.java?rev=661450&r1=661449&r2=661450&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlWidgetRenderer.java (original)
> +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlWidgetRenderer.java Thu May 29 12:48:24 2008
> @@ -21,7 +21,7 @@
> import java.io.IOException;
> import java.io.Writer;
>
> -import org.ofbiz.base.util.Debug;
> +import org.ofbiz.base.util.UtilHttp;
> import org.ofbiz.widget.ModelWidget;
>
> /**
> @@ -114,4 +114,17 @@
>             buffer.append(this.buildBoundaryComment("End",  
> widgetType, modelWidget.getBoundaryCommentName()));
>         }
>     }
> +
> +    /** Extracts parameters from a target URL string, prepares them  
> for an Ajax
> +     * JavaScript call. This method is currently set to return a  
> parameter string
> +     * suitable for the Prototype.js library.
> +     * @param target Target URL string
> +     * @return Parameter string
> +     */
> +    public static String getAjaxParamsFromTarget(String target) {
> +        String targetParams =  
> UtilHttp.getQueryStringFromTarget(target);
> +        targetParams = targetParams.replace("?", "");
> +        targetParams = targetParams.replace("&amp;", "&");
> +        return targetParams;
> +    }
> }
>
>


Re: svn commit: r661450 - in /ofbiz/trunk/framework: common/webcommon/includes/ example/webapp/example/WEB-INF/actions/includes/ example/widget/example/ images/webapp/images/ widget/dtd/ widget/src/org/ofbiz/widget/form/ widget/src/org/ofbiz/widget/html/

Posted by Jacopo Cappellato <ja...@gmail.com>.
I agree with Anil that there may be many different types of on-field- 
event-update-area

If we want to keep things simple we may just add some attributes to  
the on-field-event-update-area element; for example:

<on-field-event-update-area event-type="change" area- 
id="exampleFeatureId" area-target="findExampleFeatures" type="text- 
server-autocomplete"/>

Just my 2 cents,

Jacopo


I'm sorry if I am saying something that is not in the c
On Jun 6, 2008, at 7:58 PM, Adrian Crum wrote:

> Anil Patel wrote:
>> The way its implemented in this commit is very specialized use. On  
>> change in textbox a dropdown appears and user can navigate in that  
>> list and select a option. This is a clearly a very specialized  
>> handling of form event and expected user Interaction. Unless  
>> somebody looks at the implementation code its hard figure out.
>> I think we should add a sub element <use-server-autocomplete> and  
>> this element can have attributes and sub elements that we may need  
>> to pass to the Ajax.Autocompleter control of Script.Aculo.us.
>
> That sounds good to me. My main objection to the original  
> implementation was the use of attributes - so an additional sub  
> element would be fine.
>
>> And for <on-field-event-update-area> element we should be able to  
>> pass in  name of event handler function name. Developer can use  
>> such event listeners to implement custom stuff.
>
> I'd have to see an example. I'm not sure what you mean here.
>
> -Adrian


Re: svn commit: r661450 - in /ofbiz/trunk/framework: common/webcommon/includes/ example/webapp/example/WEB-INF/actions/includes/ example/widget/example/ images/webapp/images/ widget/dtd/ widget/src/org/ofbiz/widget/form/ widget/src/org/ofbiz/widget/html/

Posted by Adrian Crum <ad...@hlmksw.com>.
Anil Patel wrote:
> The way its implemented in this commit is very specialized use. On 
> change in textbox a dropdown appears and user can navigate in that list 
> and select a option. This is a clearly a very specialized handling of 
> form event and expected user Interaction. Unless somebody looks at the 
> implementation code its hard figure out.
> 
> I think we should add a sub element <use-server-autocomplete> and this 
> element can have attributes and sub elements that we may need to pass to 
> the Ajax.Autocompleter control of Script.Aculo.us.

That sounds good to me. My main objection to the original implementation 
was the use of attributes - so an additional sub element would be fine.

> And for <on-field-event-update-area> element we should be able to pass 
> in  name of event handler function name. Developer can use such event 
> listeners to implement custom stuff.

I'd have to see an example. I'm not sure what you mean here.

-Adrian