diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Bind.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Bind.java new file mode 100644 index 000000000..bee8dcc98 --- /dev/null +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Bind.java @@ -0,0 +1,213 @@ +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.dojo.components; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.views.annotations.StrutsTag; +import org.apache.struts2.views.annotations.StrutsTagAttribute; +import org.apache.struts2.views.annotations.StrutsTagSkipInheritance; + +import com.opensymphony.xwork2.util.ValueStack; + +/** + * + *
+ * This tag will generated event listeners for multiple events on multiple sources, + * making an asynchronous request to the specified href, and updating multiple targets. + *
+ * + *Examples
+ * + *
+ * <img id="indicator" src="${pageContext.request.contextPath}/images/indicator.gif" alt="Loading..." style="display:none"/>
+ * <sx:bind id="ex1" href="%{#ajaxTest}" sources="button" targets="div1" events="onclick" indicator="indicator" />
+ * <s:submit theme="simple" type="submit" value="submit" id="button"/>
+ *
+ *
+ *
+ *
+ * <sx:bind id="ex3" href="%{#ajaxTest}" sources="chk1" targets="div1" events="onchange" formId="form1" />
+ * <form id="form1">
+ * <s:checkbox name="data" label="Hit me" id="chk1"/>
+ * </form>
+ *
+ *
+ */
+@StrutsTag(name="bind", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.BindTag", description="Attach event listeners to elements to make AJAX calls")
+@StrutsTagSkipInheritance
+public class Bind extends AbstractRemoteCallUIBean {
+ public static final String TEMPLATE = "bind-close";
+ public static final String OPEN_TEMPLATE = "bind";
+
+ protected String targets;
+ protected String sources;
+ protected String events;
+
+ public Bind(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
+ super(stack, request, response);
+ }
+
+ public String getDefaultOpenTemplate() {
+ return OPEN_TEMPLATE;
+ }
+
+ protected String getDefaultTemplate() {
+ return TEMPLATE;
+ }
+
+ public void evaluateExtraParams() {
+ super.evaluateExtraParams();
+
+ if(targets != null)
+ addParameter("targets", findString(targets));
+ if(sources != null)
+ addParameter("sources", findString(sources));
+ if(events != null)
+ addParameter("events", findString(events));
+ }
+
+ @StrutsTagAttribute(description="Comma delimited list of event names to attach to", required=true)
+ public void setEvents(String events) {
+ this.events = events;
+ }
+
+ @StrutsTagAttribute(description="Comma delimited list of ids of the elements to attach to", required=true)
+ public void setSources(String sources) {
+ this.sources = sources;
+ }
+
+ @StrutsTagAttribute(description="Comma delimited list of ids of the elements whose content will be updated")
+ public void setTargets(String targets) {
+ this.targets = targets;
+ }
+
+ @Override
+ @StrutsTagSkipInheritance
+ public void setTheme(String theme) {
+ super.setTheme(theme);
+ }
+
+ @Override
+ public String getTheme() {
+ return "ajax";
+ }
+
+ @StrutsTagAttribute(description="Topic that will trigger the remote call")
+ public void setListenTopics(String listenTopics) {
+ this.listenTopics = listenTopics;
+ }
+
+ @StrutsTagAttribute(description="The URL to call to obtain the content. Note: If used with ajax context, the value must be set as an url tag value.")
+ public void setHref(String href) {
+ this.href = href;
+ }
+
+
+ @StrutsTagAttribute(description="The text to display to the user if the is an error fetching the content")
+ public void setErrorText(String errorText) {
+ this.errorText = errorText;
+ }
+
+ @StrutsTagAttribute(description="Javascript code in the fetched content will be executed", type="Boolean", defaultValue="false")
+ public void setExecuteScripts(String executeScripts) {
+ this.executeScripts = executeScripts;
+ }
+
+ @StrutsTagAttribute(description="Text to be shown while content is being fetched", defaultValue="Loading...")
+ public void setLoadingText(String loadingText) {
+ this.loadingText = loadingText;
+ }
+
+
+ @StrutsTagAttribute(description="Javascript function name that will make the request")
+ public void setHandler(String handler) {
+ this.handler = handler;
+ }
+
+
+ @StrutsTagAttribute(description="Function name used to filter the fields of the form.")
+ public void setFormFilter(String formFilter) {
+ this.formFilter = formFilter;
+ }
+
+ @StrutsTagAttribute(description="Form id whose fields will be serialized and passed as parameters")
+ public void setFormId(String formId) {
+ this.formId = formId;
+ }
+
+ @StrutsTagAttribute(description="Comma delimmited list of topics that will published before and after the request, and on errors")
+ public void setNotifyTopics(String notifyTopics) {
+ this.notifyTopics = notifyTopics;
+ }
+
+
+ @StrutsTagAttribute(description="Set whether errors will be shown or not", type="Boolean", defaultValue="true")
+ public void setShowErrorTransportText(String showError) {
+ this.showErrorTransportText = showError;
+ }
+
+ @StrutsTagAttribute(description="Id of element that will be shown while making request")
+ public void setIndicator(String indicator) {
+ this.indicator = indicator;
+ }
+
+ @StrutsTagAttribute(description="Show loading text on targets", type="Boolean", defaultValue="true")
+ public void setShowLoadingText(String showLoadingText) {
+ this.showLoadingText = showLoadingText;
+ }
+
+ @StrutsTagSkipInheritance
+ public void setCssClass(String cssClass) {
+ super.setCssClass(cssClass);
+ }
+
+ @StrutsTagSkipInheritance
+ public void setCssStyle(String cssStyle) {
+ super.setCssStyle(cssStyle);
+ }
+
+ @StrutsTagSkipInheritance
+ public void setName(String name) {
+ super.setName(name);
+ }
+
+ @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="The id to use for the element")
+ public void setId(String id) {
+ super.setId(id);
+ }
+}
diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java
index 45204e8dc..b30bfccea 100644
--- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java
+++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java
@@ -6,13 +6,14 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.struts2.components.Head;
import org.apache.struts2.dojo.views.freemarker.tags.DojoModels;
import org.apache.struts2.dojo.views.velocity.components.AnchorDirective;
import org.apache.struts2.dojo.views.velocity.components.AutocompleterDirective;
+import org.apache.struts2.dojo.views.velocity.components.BindDirective;
import org.apache.struts2.dojo.views.velocity.components.DateTimePickerDirective;
import org.apache.struts2.dojo.views.velocity.components.DivDirective;
import org.apache.struts2.dojo.views.velocity.components.FormDirective;
+import org.apache.struts2.dojo.views.velocity.components.HeadDirective;
import org.apache.struts2.dojo.views.velocity.components.SubmitDirective;
import org.apache.struts2.dojo.views.velocity.components.TabbedPanelDirective;
import org.apache.struts2.dojo.views.velocity.components.TreeDirective;
@@ -40,7 +41,8 @@ public class DojoTagLibrary implements TagLibrary {
TreeDirective.class,
TreeNodeDirective.class,
FormDirective.class,
- Head.class
+ HeadDirective.class,
+ BindDirective.class
};
return Arrays.asList(directives);
}
diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/BindModel.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/BindModel.java
new file mode 100644
index 000000000..a8a73305a
--- /dev/null
+++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/BindModel.java
@@ -0,0 +1,43 @@
+/*
+ * $Id: DivModel.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.dojo.views.freemarker.tags;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts2.components.Component;
+import org.apache.struts2.dojo.components.Bind;
+import org.apache.struts2.views.freemarker.tags.TagModel;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+/**
+ * @see Bind
+ */
+public class BindModel extends TagModel {
+ public BindModel(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
+ super(stack, req, res);
+ }
+
+ protected Component getBean() {
+ return new Bind(stack, req, res);
+ }
+}
diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java
index 4d6804c7b..8c6cc03f7 100644
--- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java
+++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java
@@ -19,6 +19,7 @@ public class DojoModels {
protected AnchorModel a;
protected SubmitModel submit;
protected FormModel form;
+ protected BindModel bind;
private ValueStack stack;
private HttpServletRequest req;
@@ -30,6 +31,14 @@ public class DojoModels {
this.res = res;
}
+ public BindModel getBind() {
+ if (bind == null) {
+ bind = new BindModel(stack, req, res);
+ }
+
+ return bind;
+ }
+
public DateTimePickerModel getDatetimepicker() {
if (dateTimePicker == null) {
dateTimePicker = new DateTimePickerModel(stack, req, res);
diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/BindTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/BindTag.java
new file mode 100644
index 000000000..154f355ab
--- /dev/null
+++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/BindTag.java
@@ -0,0 +1,60 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.dojo.views.jsp.ui;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts2.components.Component;
+import org.apache.struts2.dojo.components.Bind;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+public class BindTag extends AbstractRemoteCallUITag {
+ protected String targets;
+ protected String sources;
+ protected String events;
+
+ public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
+ return new Bind(stack, req, res);
+ }
+
+ protected void populateParams() {
+ super.populateParams();
+
+ Bind bind = (Bind) component;
+ bind.setTargets(targets);
+ bind.setSources(sources);
+ bind.setEvents(events);
+ }
+
+ public void setEvents(String events) {
+ this.events = events;
+ }
+
+ public void setSources(String sources) {
+ this.sources = sources;
+ }
+
+ public void setTargets(String targets) {
+ this.targets = targets;
+ }
+}
diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/velocity/components/BindDirective.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/velocity/components/BindDirective.java
new file mode 100644
index 000000000..34e167a5a
--- /dev/null
+++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/velocity/components/BindDirective.java
@@ -0,0 +1,43 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.dojo.views.velocity.components;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts2.components.Component;
+import org.apache.struts2.dojo.components.Bind;
+import org.apache.struts2.views.velocity.components.AbstractDirective;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+/**
+ * @see Bind
+ */
+public class BindDirective extends AbstractDirective {
+ public String getBeanName() {
+ return "bind";
+ }
+
+ protected Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
+ return new Bind(stack, req, res);
+ }
+}
\ No newline at end of file
diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js
index e947089c2..58c571979 100644
--- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js
+++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js
@@ -1,7 +1,7 @@
dojo.provide("struts.widget.Bind");
dojo.require("dojo.widget.HtmlWidget");
-dojo.require("dojo.io");
+dojo.require("dojo.io.*");
dojo.widget.defineWidget(
"struts.widget.Bind",
@@ -34,7 +34,7 @@ dojo.widget.defineWidget(
formFilter : "",
formNode : null,
- event : "",
+ events : "",
indicator : "",
parseContent : true,
@@ -77,14 +77,20 @@ dojo.widget.defineWidget(
this.targetsArray = this.targets.split(",");
}
- if(!dojo.string.isBlank(this.event)) {
- dojo.event.connect(this.domNode, this.event, function(evt) {
- evt.preventDefault();
- evt.stopPropagation();
- self.reloadContents();
- });
+ if(!dojo.string.isBlank(this.events)) {
+ var eventsArray = this.events.split(",");
+ if(eventsArray && this.domNode) {
+ dojo.lang.forEach(eventsArray, function(event){
+ dojo.event.connect(self.domNode, event, function(evt) {
+ evt.preventDefault();
+ evt.stopPropagation();
+ self.reloadContents();
+ });
+ });
+ }
}
+
if(dojo.string.isBlank(this.href) && dojo.string.isBlank(this.formId)) {
//no href and no formId, we must be inside a form
this.formNode = dojo.dom.getFirstAncestorByTag(this.domNode, "form");
@@ -111,12 +117,16 @@ dojo.widget.defineWidget(
var xmlParser = new dojo.xml.Parse();
dojo.lang.forEach(this.targetsArray, function(target) {
var node = dojo.byId(target);
- node.innerHTML = text;
-
- if(self.parseContent && text != self.loadingText){
- var frag = xmlParser.parseElement(node, null, true);
- dojo.widget.getParser().createSubComponents(frag, dojo.widget.byId(target));
- }
+ if(node) {
+ node.innerHTML = text;
+
+ if(self.parseContent && text != self.loadingText){
+ var frag = xmlParser.parseElement(node, null, true);
+ dojo.widget.getParser().createSubComponents(frag, dojo.widget.byId(target));
+ }
+ } else {
+ self.log("Unable to find target: " + node);
+ }
});
}
},
@@ -187,11 +197,11 @@ dojo.widget.defineWidget(
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);
- }
+ try {
+ dojo.event.topic.publish(topic, data, type, e);
+ } catch(ex){
+ self.log(ex);
+ }
});
}
},
diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindAnchor.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindAnchor.js
index 20d8de7f1..0592ae1c0 100644
--- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindAnchor.js
+++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindAnchor.js
@@ -1,7 +1,7 @@
dojo.provide("struts.widget.BindAnchor");
dojo.require("dojo.widget.HtmlWidget");
-dojo.require("dojo.io");
+dojo.require("dojo.io.*");
dojo.require("struts.widget.Bind");
dojo.widget.defineWidget(
@@ -9,7 +9,7 @@ dojo.widget.defineWidget(
struts.widget.Bind, {
widgetType : "BindAnchor",
- event: "onclick",
+ events: "onclick",
postCreate : function() {
struts.widget.BindAnchor.superclass.postCreate.apply(this);
diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js
index 7c5810d08..0509d184d 100644
--- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js
+++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindDiv.js
@@ -1,6 +1,6 @@
dojo.provide("struts.widget.BindDiv");
-dojo.require("dojo.io");
+dojo.require("dojo.io.*");
dojo.require("dojo.widget.ContentPane");
dojo.require("dojo.lang.timing.Timer");
diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindEvent.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindEvent.js
new file mode 100644
index 000000000..7d4cdbcc1
--- /dev/null
+++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/BindEvent.js
@@ -0,0 +1,38 @@
+dojo.provide("struts.widget.BindEvent");
+
+dojo.require("struts.widget.Bind");
+
+dojo.widget.defineWidget(
+ "struts.widget.BindEvent",
+ struts.widget.Bind, {
+ widgetType : "BindEvent",
+
+ sources: "",
+
+ postCreate : function() {
+ struts.widget.BindEvent.superclass.postCreate.apply(this);
+ var self = this;
+
+ if(!dojo.string.isBlank(this.events) && !dojo.string.isBlank(this.sources)) {
+ var eventsArray = this.events.split(",");
+ var sourcesArray = this.sources.split(",");
+
+ if(eventsArray && this.domNode) {
+ //events
+ dojo.lang.forEach(eventsArray, function(event) {
+ //sources
+ dojo.lang.forEach(sourcesArray, function(source) {
+ var sourceObject = dojo.byId(source);
+ if(sourceObject) {
+ dojo.event.connect(sourceObject, event, function(evt) {
+ evt.preventDefault();
+ evt.stopPropagation();
+ self.reloadContents();
+ });
+ }
+ });
+ });
+ }
+ }
+ }
+});
\ No newline at end of file
diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsDatePicker.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsDatePicker.js
index e311f640a..323faf2e9 100644
--- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsDatePicker.js
+++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/StrutsDatePicker.js
@@ -1,7 +1,6 @@
dojo.provide("struts.widget.StrutsDatePicker");
dojo.require("dojo.widget.DropdownDatePicker");
-dojo.requireLocalization("dojo.widget", "StrutsDatePicker");
dojo.widget.defineWidget(
"struts.widget.StrutsDatePicker",
dojo.widget.DropdownDatePicker, {
diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js
index 14d1127ba..24a44b119 100644
--- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js
+++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/__package__.js
@@ -4,6 +4,7 @@ dojo.kwCompoundRequire({
"struts.widget.BindAnchor",
"struts.widget.ComboBox",
"struts.widget.StrutsTimePicker",
- "struts.widget.StrutsDatePicker"]
+ "struts.widget.StrutsDatePicker",
+ "struts.widget.BindEvent"]
});
dojo.provide("struts.widget.*");
diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js
index 08f624816..e4448db4f 100644
--- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js
+++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js
@@ -13599,7 +13599,7 @@ self.addKeyHandler(item[1]?item[1]:item[0].charAt(0),item[2]==undefined?self.KEY
});
}});
dojo.provide("struts.widget.Bind");
-dojo.widget.defineWidget("struts.widget.Bind",dojo.widget.HtmlWidget,{widgetType:"Bind",executeScripts:false,targets:"",targetsArray:null,href:"",handler:"",loadingText:"Loading...",errorText:"",showError:true,showLoading:true,listenTopics:"",notifyTopics:"",notifyTopicsArray:null,beforeNotifyTopics:"",beforeNotifyTopicsArray:null,afterNotifyTopics:"",afterNotifyTopicsArray:null,errorNotifyTopics:"",errorNotifyTopicsArray:null,formId:"",formFilter:"",formNode:null,event:"",indicator:"",parseContent:true,postCreate:function(){
+dojo.widget.defineWidget("struts.widget.Bind",dojo.widget.HtmlWidget,{widgetType:"Bind",executeScripts:false,targets:"",targetsArray:null,href:"",handler:"",loadingText:"Loading...",errorText:"",showError:true,showLoading:true,listenTopics:"",notifyTopics:"",notifyTopicsArray:null,beforeNotifyTopics:"",beforeNotifyTopicsArray:null,afterNotifyTopics:"",afterNotifyTopicsArray:null,errorNotifyTopics:"",errorNotifyTopicsArray:null,formId:"",formFilter:"",formNode:null,events:"",indicator:"",parseContent:true,postCreate:function(){
var self=this;
if(!dojo.string.isBlank(this.listenTopics)){
this.log("Listening to "+this.listenTopics+" to refresh");
@@ -13625,12 +13625,17 @@ this.errorNotifyTopicsArray=this.errorNotifyTopics.split(",");
if(!dojo.string.isBlank(this.targets)){
this.targetsArray=this.targets.split(",");
}
-if(!dojo.string.isBlank(this.event)){
-dojo.event.connect(this.domNode,this.event,function(evt){
+if(!dojo.string.isBlank(this.events)){
+var _b75=this.events.split(",");
+if(_b75&&this.domNode){
+dojo.lang.forEach(_b75,function(_b76){
+dojo.event.connect(self.domNode,_b76,function(evt){
evt.preventDefault();
evt.stopPropagation();
self.reloadContents();
});
+});
+}
}
if(dojo.string.isBlank(this.href)&&dojo.string.isBlank(this.formId)){
this.formNode=dojo.dom.getFirstAncestorByTag(this.domNode,"form");
@@ -13648,13 +13653,17 @@ dojo.debug("["+(this.widgetId?this.widgetId:"unknown")+"] "+text);
},setContent:function(text){
if(this.targetsArray){
var self=this;
-var _b79=new dojo.xml.Parse();
-dojo.lang.forEach(this.targetsArray,function(_b7a){
-var node=dojo.byId(_b7a);
+var _b7b=new dojo.xml.Parse();
+dojo.lang.forEach(this.targetsArray,function(_b7c){
+var node=dojo.byId(_b7c);
+if(node){
node.innerHTML=text;
if(self.parseContent&&text!=self.loadingText){
-var frag=_b79.parseElement(node,null,true);
-dojo.widget.getParser().createSubComponents(frag,dojo.widget.byId(_b7a));
+var frag=_b7b.parseElement(node,null,true);
+dojo.widget.getParser().createSubComponents(frag,dojo.widget.byId(_b7c));
+}
+}else{
+self.log("Unable to find target: "+node);
}
});
}
@@ -13663,64 +13672,64 @@ dojo.html.hide(this.indicator);
this.notify(data,type,e);
if(type=="load"){
if(this.executeScripts){
-var _b80=this.parse(data);
-if(_b80.scripts&&_b80.scripts.length>0){
-var _b81="";
-for(var i=0;i<_b80.scripts.length;i++){
-_b81+=_b80.scripts[i];
+var _b82=this.parse(data);
+if(_b82.scripts&&_b82.scripts.length>0){
+var _b83="";
+for(var i=0;i<_b82.scripts.length;i++){
+_b83+=_b82.scripts[i];
}
-(new Function("_container_",_b81+"; return this;"))(this);
+(new Function("_container_",_b83+"; return this;"))(this);
}
-this.setContent(_b80.text);
+this.setContent(_b82.text);
}else{
this.setContent(data);
}
}else{
if(this.showError){
-var _b83=dojo.string.isBlank(this.errorText)?e.message:this.errorText;
-this.setContent(_b83);
+var _b85=dojo.string.isBlank(this.errorText)?e.message:this.errorText;
+this.setContent(_b85);
}
}
},notify:function(data,type,e){
var self=this;
if(this.notifyTopicsArray){
-dojo.lang.forEach(this.notifyTopicsArray,function(_b88){
+dojo.lang.forEach(this.notifyTopicsArray,function(_b8a){
try{
-dojo.event.topic.publish(_b88,data,type,e);
+dojo.event.topic.publish(_b8a,data,type,e);
}
catch(ex){
self.log(ex);
}
});
}
-var _b89=null;
+var _b8b=null;
switch(type){
case "before":
-_b89=this.beforeNotifyTopicsArray;
+_b8b=this.beforeNotifyTopicsArray;
break;
case "load":
-_b89=this.afterNotifyTopicsArray;
+_b8b=this.afterNotifyTopicsArray;
break;
case "error":
-_b89=this.errorNotifyTopicsArray;
+_b8b=this.errorNotifyTopicsArray;
break;
}
-this.notifyTo(_b89,data,type,e);
-},notifyTo:function(_b8a,data,type,e){
+this.notifyTo(_b8b,data,type,e);
+},notifyTo:function(_b8c,data,type,e){
var self=this;
-if(_b8a){
-dojo.lang.forEach(_b8a,function(_b8f){
+if(_b8c){
+dojo.lang.forEach(_b8c,function(_b91){
try{
-dojo.event.topic.publish(_b8f,data,type,e);
+dojo.event.topic.publish(_b91,data,type,e);
}
catch(ex){
self.log(ex);
}
});
}
-},onDownloadStart:function(_b90){
+},onDownloadStart:function(_b92){
if(this.showLoading&&!dojo.string.isBlank(this.loadingText)){
-_b90.text=this.loadingText;
+_b92.text=this.loadingText;
}
},reloadContents:function(evt){
if(!dojo.string.isBlank(this.handler)){
@@ -13729,9 +13738,9 @@ window[this.handler](this,this.domNode);
}else{
try{
var self=this;
-var _b93={cancel:false};
-this.notify(this.widgetId,"before",_b93);
-if(_b93.cancel){
+var _b95={cancel:false};
+this.notify(this.widgetId,"before",_b95);
+if(_b95.cancel){
this.log("Request canceled");
return;
}
@@ -13739,8 +13748,8 @@ if(dojo.string.isBlank(this.href)){
return;
}
if(this.formNode&&this.formNode.onsubmit!=null){
-var _b94=this.formNode.onsubmit.call(evt);
-if(_b94!=null&&!_b94){
+var _b96=this.formNode.onsubmit.call(evt);
+if(_b96!=null&&!_b96){
this.log("Request canceled by 'onsubmit' of the form");
return;
}
@@ -13755,23 +13764,23 @@ dojo.lang.hitch(self,"bindHandler")(type,data,e);
}
catch(ex){
if(this.showError){
-var _b98=dojo.string.isBlank(this.errorText)?ex:this.errorText;
-this.setContent(_b98);
+var _b9a=dojo.string.isBlank(this.errorText)?ex:this.errorText;
+this.setContent(_b9a);
}
}
}
},parse:function(s){
this.log("Parsing: "+s);
-var _b9a=[];
-var tmp=[];
var _b9c=[];
-while(_b9a){
-_b9a=s.match(/
\ No newline at end of file
diff --git a/plugins/dojo/src/main/resources/template/ajax/dojoRequire.js b/plugins/dojo/src/main/resources/template/ajax/dojoRequire.js
index 822ca7126..988c43010 100644
--- a/plugins/dojo/src/main/resources/template/ajax/dojoRequire.js
+++ b/plugins/dojo/src/main/resources/template/ajax/dojoRequire.js
@@ -5,11 +5,6 @@ dojo.hostenv.setModulePrefix('struts', 'struts');
dojo.require('dojo.widget.*');
dojo.widget.manager.registerWidgetPackage('struts.widget');
-dojo.require("struts.widget.Bind");
-dojo.require("struts.widget.BindDiv");
-dojo.require("struts.widget.BindAnchor");
-dojo.require("struts.widget.ComboBox");
-dojo.require("struts.widget.StrutsTimePicker")
-dojo.require("struts.widget.StrutsDatePicker")
+dojo.require("struts.widget.*");
dojo.require("dojo.widget.Editor2");
dojo.hostenv.writeIncludes(); // not needed, but allows the Venkman debugger to work with the includes
diff --git a/plugins/dojo/src/main/resources/template/ajax/submit.ftl b/plugins/dojo/src/main/resources/template/ajax/submit.ftl
index b35eda110..0ce7d4eb3 100644
--- a/plugins/dojo/src/main/resources/template/ajax/submit.ftl
+++ b/plugins/dojo/src/main/resources/template/ajax/submit.ftl
@@ -1,5 +1,5 @@
<#if parameters.type?exists && parameters.type=="button">
-
+
<#include "/${parameters.templateDir}/ajax/ajax-common.ftl"/>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl"/>
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
@@ -9,7 +9,7 @@
/>
<#else>
<#if parameters.type?exists && parameters.type=="image">
-
+
<#if parameters.label?if_exists != "">
alt="${parameters.label?html}"<#rt/>
#if>
@@ -17,7 +17,7 @@
src="${parameters.src?html}"<#rt/>
#if>
<#else>
-
+
#if>
<#if parameters.nameValue?if_exists != "">
value="${parameters.nameValue?html}"<#rt/>
diff --git a/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/BindTest.java b/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/BindTest.java
new file mode 100644
index 000000000..e8976494e
--- /dev/null
+++ b/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/BindTest.java
@@ -0,0 +1,33 @@
+package org.apache.struts2.dojo.views.jsp.ui;
+
+import org.apache.struts2.dojo.TestAction;
+
+public class BindTest extends AbstractUITagTest {
+ public void testSubmit() throws Exception {
+ TestAction testAction = (TestAction) action;
+ testAction.setFoo("bar");
+
+ BindTag tag = new BindTag();
+ tag.setPageContext(pageContext);
+
+ tag.setId("a");
+ tag.setHref("b");
+ tag.setLoadingText("c");
+ tag.setErrorText("d");
+ tag.setListenTopics("e");
+ tag.setBeforeNotifyTopics("f");
+ tag.setAfterNotifyTopics("g");
+ tag.setHandler("h");
+ tag.setLabel("i");
+ tag.setNotifyTopics("k");
+ tag.setIndicator("l");
+ tag.setShowLoadingText("true");
+ tag.setErrorNotifyTopics("m");
+ tag.setSources("n");
+ tag.setEvents("o");
+ tag.doStartTag();
+ tag.doEndTag();
+
+ verify(BindTest.class.getResource("Bind-1.txt"));
+ }
+}
diff --git a/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Bind-1.txt b/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Bind-1.txt
new file mode 100644
index 000000000..a69b122b8
--- /dev/null
+++ b/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/Bind-1.txt
@@ -0,0 +1,17 @@
+
\ No newline at end of file
diff --git a/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/submit-ajax-1.txt b/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/submit-ajax-1.txt
index d13a55632..b9321d6d3 100644
--- a/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/submit-ajax-1.txt
+++ b/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/submit-ajax-1.txt
@@ -1,7 +1,7 @@