WW-1607 Add ajax notify topics to autocompleter

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@521551 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2007-03-23 00:51:54 +00:00
parent 01ad6b200e
commit a77ea70bed
10 changed files with 145 additions and 11 deletions
@@ -72,7 +72,7 @@ Disabled combobox (disabled="true")
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"/>
@@ -71,6 +71,10 @@ public class Autocompleter extends ComboBox {
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 @@ public class Autocompleter extends ComboBox {
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
@@ -292,4 +305,24 @@ public class Autocompleter extends ComboBox {
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;
}
}
@@ -55,6 +55,10 @@ public class AutocompleterTag extends ComboBoxTag {
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 @@ public class AutocompleterTag extends ComboBoxTag {
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) {
@@ -169,4 +177,20 @@ public class AutocompleterTag extends ComboBoxTag {
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;
}
}
@@ -183,12 +183,12 @@ dojo.widget.defineWidget(
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);
}
@@ -117,12 +117,12 @@ dojo.widget.defineWidget(
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);
}
@@ -59,8 +59,9 @@ struts.widget.ComboBoxDataProvider = function(/*Array*/ dataPairs, /*Number*/ li
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 @@ struts.widget.ComboBoxDataProvider = function(/*Array*/ dataPairs, /*Number*/ li
data = arrData;
}
this.setData(data);
this.firstRequest = false;
}),
mimetype: "text/json"
});
@@ -215,7 +215,14 @@ dojo.widget.defineWidget(
listenTopics : "",
notifyTopics : "",
notifyTopicsArray : null,
beforeNotifyTopics : "",
beforeNotifyTopicsArray : null,
afterNotifyTopics : "",
afterNotifyTopicsArray : null,
errorNotifyTopics : "",
errorNotifyTopicsArray : null,
valueNotifyTopics : "",
valueNotifyTopicsArray : null,
indicator : "",
formId : "",
@@ -234,7 +241,7 @@ dojo.widget.defineWidget(
//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 @@ dojo.widget.defineWidget(
}
}
//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 @@ dojo.widget.defineWidget(
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);
}
});
}
@@ -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>
@@ -47,6 +47,7 @@ public class AutocompleterTest extends AbstractUITagTest {
tag.setIconPath("i");
tag.setTemplateCssPath("j");
tag.setDataFieldName("k");
tag.setValueNotifyTopics("l");
tag.doStartTag();
tag.doEndTag();
@@ -68,6 +69,7 @@ public class AutocompleterTest extends AbstractUITagTest {
tag.setName("f");
tag.setIconPath("i");
tag.setTemplateCssPath("j");
tag.setValueNotifyTopics("k");
tag.doStartTag();
tag.doEndTag();
@@ -11,6 +11,7 @@
name="f"
keyName="i"
initialValue="g"
valueNotifyTopics="l"
indicator="h"
loadOnType="true"
loadMinimum="3"
@@ -9,6 +9,7 @@
dropdownHeight="10"
name="f"
keyName="fKey"
valueNotifyTopics="k"
visibleDownArrow="true"
buttonSrc="i"
templateCssPath="j"