Author: musachy Date: Thu Mar 22 17:51:54 2007 New Revision: 521551 URL: http://svn.apache.org/viewvc?view=rev&rev=521551 Log: WW-1607 Add ajax notify topics to autocompleter
Modified: struts/struts2/trunk/apps/showcase/src/main/webapp/ajax/autocompleter/index.jsp struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTag.java struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/autocompleter.ftl struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTest.java struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-1.txt struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-2.txt Modified: struts/struts2/trunk/apps/showcase/src/main/webapp/ajax/autocompleter/index.jsp URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/ajax/autocompleter/index.jsp?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/apps/showcase/src/main/webapp/ajax/autocompleter/index.jsp (original) +++ struts/struts2/trunk/apps/showcase/src/main/webapp/ajax/autocompleter/index.jsp Thu Mar 22 17:51:54 2007 @@ -72,7 +72,7 @@ Link two autocompleter elements. When the selected value in 'Autocompleter 1' changes, the available values in 'Autocompleter 2' will change also. <br/> <form id="selectForm"> - <p>Autocompleter 1 <sx:autocompleter name="select" list="{'fruits','colors'}" value="colors" notifyTopics="/Changed" forceValidOption="true" id="sel"/></p> + <p>Autocompleter 1 <sx:autocompleter name="select" list="{'fruits','colors'}" value="colors" valueNotifyTopics="/Changed" forceValidOption="true" id="sel"/></p> </form> Autocompleter 2 <sx:autocompleter href="%{#autoex}" autoComplete="false" formId="selectForm" listenTopics="/Changed" forceValidOption="true" id="ops"/> Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java (original) +++ struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java Thu Mar 22 17:51:54 2007 @@ -71,6 +71,10 @@ protected String iconPath; protected String keyName; protected String dataFieldName; + protected String beforeNotifyTopics; + protected String afterNotifyTopics; + protected String errorNotifyTopics; + protected String valueNotifyTopics; public Autocompleter(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { @@ -144,6 +148,15 @@ String keyNameExpr = "%{" + keyName + "}"; addParameter("key", findString(keyNameExpr)); + + if (beforeNotifyTopics != null) + addParameter("beforeNotifyTopics", findString(beforeNotifyTopics)); + if (afterNotifyTopics != null) + addParameter("afterNotifyTopics", findString(afterNotifyTopics)); + if (errorNotifyTopics != null) + addParameter("errorNotifyTopics", findString(errorNotifyTopics)); + if (valueNotifyTopics != null) + addParameter("valueNotifyTopics", findString(valueNotifyTopics)); } @Override @@ -291,5 +304,25 @@ @StrutsTagAttribute(description="Preset the value of input element") public void setValue(String arg0) { super.setValue(arg0); + } + + @StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request succeeds)") + public void setAfterNotifyTopics(String afterNotifyTopics) { + this.afterNotifyTopics = afterNotifyTopics; + } + + @StrutsTagAttribute(description="Comma delimmited list of topics that will published before the request") + public void setBeforeNotifyTopics(String beforeNotifyTopics) { + this.beforeNotifyTopics = beforeNotifyTopics; + } + + @StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request fails)") + public void setErrorNotifyTopics(String errorNotifyTopics) { + this.errorNotifyTopics = errorNotifyTopics; + } + + @StrutsTagAttribute(description="Comma delimmited list of topics that will published when a value is selected") + public void setValueNotifyTopics(String valueNotifyTopics) { + this.valueNotifyTopics = valueNotifyTopics; } } Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTag.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTag.java?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTag.java (original) +++ struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTag.java Thu Mar 22 17:51:54 2007 @@ -55,6 +55,10 @@ protected String iconPath; protected String keyName; protected String dataFieldName; + protected String beforeNotifyTopics; + protected String afterNotifyTopics; + protected String errorNotifyTopics; + protected String valueNotifyTopics; public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { return new Autocompleter(stack, req, res); @@ -84,6 +88,10 @@ autocompleter.setIconPath(iconPath); autocompleter.setKeyName(keyName); autocompleter.setDataFieldName(dataFieldName); + autocompleter.setAfterNotifyTopics(afterNotifyTopics); + autocompleter.setBeforeNotifyTopics(beforeNotifyTopics); + autocompleter.setErrorNotifyTopics(errorNotifyTopics); + autocompleter.setValueNotifyTopics(valueNotifyTopics); } public void setAutoComplete(String autoComplete) { @@ -168,5 +176,21 @@ public void setDataFieldName(String dataFieldName) { this.dataFieldName = dataFieldName; + } + + public void setAfterNotifyTopics(String afterNotifyTopics) { + this.afterNotifyTopics = afterNotifyTopics; + } + + public void setBeforeNotifyTopics(String beforeNotifyTopics) { + this.beforeNotifyTopics = beforeNotifyTopics; + } + + public void setErrorNotifyTopics(String errorNotifyTopics) { + this.errorNotifyTopics = errorNotifyTopics; + } + + public void setValueNotifyTopics(String valueNotifyTopics) { + this.valueNotifyTopics = valueNotifyTopics; } } Modified: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js (original) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js Thu Mar 22 17:51:54 2007 @@ -183,12 +183,12 @@ this.notifyTo(topicsArray, data, type, e); }, - notifyTo : function(topicsArray, data, e) { + notifyTo : function(topicsArray, data, type, e) { var self = this; if(topicsArray) { dojo.lang.forEach(topicsArray, function(topic) { try { - dojo.event.topic.publish(topic, data, e); + dojo.event.topic.publish(topic, data, type, e); } catch(ex){ self.log(ex); } Modified: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js (original) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js Thu Mar 22 17:51:54 2007 @@ -117,12 +117,12 @@ this.notifyTo(topicsArray, data, type, e); }, - notifyTo : function(topicsArray, data, e) { + notifyTo : function(topicsArray, data, type, e) { var self = this; if(topicsArray) { dojo.lang.forEach(topicsArray, function(topic) { try { - dojo.event.topic.publish(topic, data, e); + dojo.event.topic.publish(topic, data, type, e); } catch(ex){ self.log(ex); } Modified: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js (original) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js Thu Mar 22 17:51:54 2007 @@ -59,8 +59,9 @@ url: url, formNode: dojo.byId(this.formId), formFilter: window[this.formFilter], - load: dojo.lang.hitch(this, function(type, data, evt) { - //show indicator + handler: dojo.lang.hitch(this, function(type, data, evt) { + this.firstRequest = false; + //hide indicator dojo.html.hide(this.cbox.indicator); //if notifyTopics is published on the first request (onload) @@ -92,7 +93,6 @@ data = arrData; } this.setData(data); - this.firstRequest = false; }), mimetype: "text/json" }); @@ -215,7 +215,14 @@ listenTopics : "", notifyTopics : "", notifyTopicsArray : null, - + beforeNotifyTopics : "", + beforeNotifyTopicsArray : null, + afterNotifyTopics : "", + afterNotifyTopicsArray : null, + errorNotifyTopics : "", + errorNotifyTopicsArray : null, + valueNotifyTopics : "", + valueNotifyTopicsArray : null, indicator : "", formId : "", @@ -234,7 +241,7 @@ //dojo has "stringstart" which is invalid searchType: "STARTSTRING", - dataFieldName : "" , + dataFieldName : "", keyName: "", templateCssPath: dojo.uri.dojoUri("struts/ComboBox.css"), //from Dojo's ComboBox @@ -341,9 +348,30 @@ } } + //notify topics if(!dojo.string.isBlank(this.notifyTopics)) { this.notifyTopicsArray = this.notifyTopics.split(","); } + + //before topics + if(!dojo.string.isBlank(this.beforeNotifyTopics)) { + this.beforeNotifyTopicsArray = this.beforeNotifyTopics.split(","); + } + + //after topics + if(!dojo.string.isBlank(this.afterNotifyTopics)) { + this.afterNotifyTopicsArray = this.afterNotifyTopics.split(","); + } + + //error topics + if(!dojo.string.isBlank(this.errorNotifyTopics)) { + this.errorNotifyTopicsArray = this.errorNotifyTopics.split(","); + } + + //value topics + if(!dojo.string.isBlank(this.valueNotifyTopics)) { + this.valueNotifyTopicsArray = this.valueNotifyTopics.split(","); + } //better name this.comboBoxSelectionValue.name = dojo.string.isBlank(this.keyName) ? this.name + "Key" : this.keyName; @@ -376,11 +404,44 @@ notify : function(data, type, e) { if(this.notifyTopicsArray) { + var self = this; dojo.lang.forEach(this.notifyTopicsArray, function(topic) { try { dojo.event.topic.publish(topic, data, type, e); } catch(ex) { - dojo.debug(ex); + self.log(ex); + } + }); + } + + //before, after and error topics + var topicsArray = null; + switch(type) { + case "before": + topicsArray = this.beforeNotifyTopicsArray; + break; + case "load": + topicsArray = this.afterNotifyTopicsArray; + break; + case "error": + topicsArray = this.errorNotifyTopicsArray; + break; + case "valuechanged": + topicsArray = this.valueNotifyTopicsArray; + break; + } + + this.notifyTo(topicsArray, data, type, e); + }, + + notifyTo : function(topicsArray, data, type, e) { + var self = this; + if(topicsArray) { + dojo.lang.forEach(topicsArray, function(topic) { + try { + dojo.event.topic.publish(topic, data, type, e); + } catch(ex){ + self.log(ex); } }); } Modified: struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/autocompleter.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/autocompleter.ftl?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/autocompleter.ftl (original) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/template/ajax/autocompleter.ftl Thu Mar 22 17:51:54 2007 @@ -71,6 +71,18 @@ <#if parameters.notifyTopics?if_exists != ""> notifyTopics="${parameters.notifyTopics?html}"<#rt/> </#if> +<#if parameters.beforeNotifyTopics?if_exists != ""> + beforeNotifyTopics="${parameters.beforeNotifyTopics?html}"<#rt/> +</#if> +<#if parameters.afterNotifyTopics?if_exists != ""> + afterNotifyTopics="${parameters.afterNotifyTopics?html}"<#rt/> +</#if> +<#if parameters.errorNotifyTopics?if_exists != ""> + errorNotifyTopics="${parameters.errorNotifyTopics?html}"<#rt/> +</#if> +<#if parameters.valueNotifyTopics?if_exists != ""> + valueNotifyTopics="${parameters.valueNotifyTopics?html}"<#rt/> +</#if> <#if parameters.indicator?if_exists != ""> indicator="${parameters.indicator?html}"<#rt/> </#if> Modified: struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTest.java?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTest.java (original) +++ struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/AutocompleterTest.java Thu Mar 22 17:51:54 2007 @@ -47,6 +47,7 @@ tag.setIconPath("i"); tag.setTemplateCssPath("j"); tag.setDataFieldName("k"); + tag.setValueNotifyTopics("l"); tag.doStartTag(); tag.doEndTag(); @@ -68,6 +69,7 @@ tag.setName("f"); tag.setIconPath("i"); tag.setTemplateCssPath("j"); + tag.setValueNotifyTopics("k"); tag.doStartTag(); tag.doEndTag(); Modified: struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-1.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-1.txt?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-1.txt (original) +++ struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-1.txt Thu Mar 22 17:51:54 2007 @@ -11,6 +11,7 @@ name="f" keyName="i" initialValue="g" + valueNotifyTopics="l" indicator="h" loadOnType="true" loadMinimum="3" Modified: struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-2.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-2.txt?view=diff&rev=521551&r1=521550&r2=521551 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-2.txt (original) +++ struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Autocompleter-2.txt Thu Mar 22 17:51:54 2007 @@ -9,6 +9,7 @@ dropdownHeight="10" name="f" keyName="fKey" + valueNotifyTopics="k" visibleDownArrow="true" buttonSrc="i" templateCssPath="j"