WW-1935 Tags Bind, Anchor and Submit, in the Dojo plugin should have a "separateScripts" attribute to run scripts on their own scope

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@539946 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2007-05-20 21:29:37 +00:00
parent 265d94a928
commit 9e11d44e5e
21 changed files with 1714 additions and 1507 deletions
@@ -49,6 +49,7 @@ public abstract class AbstractRemoteBean extends ClosingUIBean implements Remote
protected String errorNotifyTopics;
protected String highlightColor;
protected String highlightDuration;
protected String separateScripts;
public AbstractRemoteBean(ValueStack stack, HttpServletRequest request,
HttpServletResponse response) {
@@ -94,6 +95,8 @@ public abstract class AbstractRemoteBean extends ClosingUIBean implements Remote
addParameter("highlightColor", findString(highlightColor));
if (highlightDuration != null)
addParameter("highlightDuration", findString(highlightDuration));
if (separateScripts != null)
addParameter("separateScripts", findValue(separateScripts, Boolean.class));
}
@Override
@@ -217,4 +220,9 @@ public abstract class AbstractRemoteBean extends ClosingUIBean implements Remote
public void setHighlightDuration(String highlightDuration) {
this.highlightDuration = highlightDuration;
}
@StrutsTagAttribute(description="Run scripts in a separate scope, unique for each tag", defaultValue="true")
public void setSeparateScripts(String separateScripts) {
this.separateScripts = separateScripts;
}
}
@@ -62,4 +62,6 @@ public interface RemoteBean {
void setHighlightColor(String color);
void setHighlightDuration(String color);
void setSeparateScripts(String separateScripts);
}
@@ -122,6 +122,7 @@ public class Submit extends FormButton implements RemoteBean {
protected String highlightDuration;
protected String validate;
protected String ajaxAfterValidation;
protected String separateScripts;
public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
@@ -184,6 +185,8 @@ public class Submit extends FormButton implements RemoteBean {
addParameter("highlightColor", findString(highlightColor));
if (highlightDuration != null)
addParameter("highlightDuration", findString(highlightDuration));
if (separateScripts != null)
addParameter("separateScripts", findValue(separateScripts, Boolean.class));
Boolean validateValue = false;
if (validate != null) {
@@ -387,4 +390,9 @@ public class Submit extends FormButton implements RemoteBean {
public void setAction(String action) {
super.setAction(action);
}
@StrutsTagAttribute(description="Run scripts in a separate scope, unique for each tag", defaultValue="true")
public void setSeparateScripts(String separateScripts) {
this.separateScripts = separateScripts;
}
}
@@ -39,6 +39,7 @@ public abstract class AbstractRemoteTag extends AbstractClosingTag {
protected String errorNotifyTopics;
protected String highlightColor;
protected String highlightDuration;
protected String separateScripts;
protected void populateParams() {
super.populateParams();
@@ -61,6 +62,7 @@ public abstract class AbstractRemoteTag extends AbstractClosingTag {
remote.setErrorNotifyTopics(errorNotifyTopics);
remote.setHighlightColor(highlightColor);
remote.setHighlightDuration(highlightDuration);
remote.setSeparateScripts(separateScripts);
}
public void setHref(String href) {
@@ -130,4 +132,8 @@ public abstract class AbstractRemoteTag extends AbstractClosingTag {
public void setHighlightDuration(String highlightDuration) {
this.highlightDuration = highlightDuration;
}
public void setSeparateScripts(String separateScripts) {
this.separateScripts = separateScripts;
}
}
@@ -60,6 +60,7 @@ public class SubmitTag extends AbstractUITag {
protected String highlightDuration;
protected String validate;
protected String ajaxAfterValidation;
protected String separateScripts;
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new Submit(stack, req, res);
@@ -93,6 +94,7 @@ public class SubmitTag extends AbstractUITag {
submit.setHighlightDuration(highlightDuration);
submit.setValidate(validate);
submit.setAjaxAfterValidation(ajaxAfterValidation);
submit.setSeparateScripts(separateScripts);
}
public void setMethod(String method) {
@@ -194,4 +196,8 @@ public class SubmitTag extends AbstractUITag {
public void setAjaxAfterValidation(String ajaxAfterValidation) {
this.ajaxAfterValidation = ajaxAfterValidation;
}
public void setSeparateScripts(String separateScripts) {
this.separateScripts = separateScripts;
}
}
@@ -9,6 +9,7 @@ dojo.widget.defineWidget(
dojo.widget.HtmlWidget, {
widgetType : "Bind",
executeScripts : false,
scriptSeparation : false,
targets : "",
targetsArray : null,
href : "",
@@ -46,6 +47,13 @@ dojo.widget.defineWidget(
validate : false,
ajaxAfterValidation : false,
//used for scripts downloading & caching
cacheContent : true,
//run script on its own scope
scriptSeparation : true,
//scope for the cript separation
scriptScope : null,
postCreate : function() {
var self = this;
@@ -183,14 +191,7 @@ dojo.widget.defineWidget(
if(this.executeScripts) {
//update targets content
var parsed = this.parse(data);
//eval scripts
if(parsed.scripts && parsed.scripts.length > 0) {
var scripts = "";
for(var i = 0; i < parsed.scripts.length; i++){
scripts += parsed.scripts[i];
}
(new Function('_container_', scripts+'; return this;'))(this);
}
this._executeScripts(parsed.scripts);
this.setContent(parsed.text);
}
else {
@@ -365,7 +366,65 @@ dojo.widget.defineWidget(
text: s,
scripts: scripts
};
}
},
//from Dojo content pane
_executeScripts : function (scripts) {
var self = this;
var tmp = "", code = "";
for (var i = 0; i < scripts.length; i++) {
if (scripts[i].path) {
dojo.io.bind(this._cacheSetting({"url":scripts[i].path, "load":function (type, scriptStr) {
dojo.lang.hitch(self, tmp = ";" + scriptStr);
}, "error":function (type, error) {
error.text = type + " downloading remote script";
self._handleDefaults.call(self, error, "onExecError", "debug");
}, "mimetype":"text/plain", "sync":true}, this.cacheContent));
code += tmp;
} else {
code += scripts[i];
}
}
try {
if (this.scriptSeparation) {
delete this.scriptScope;
this.scriptScope = new (new Function("_container_", code + "; return this;"))(self);
} else {
var djg = dojo.global();
if (djg.execScript) {
djg.execScript(code);
} else {
var djd = dojo.doc();
var sc = djd.createElement("script");
sc.appendChild(djd.createTextNode(code));
(this.containerNode || this.domNode).appendChild(sc);
}
}
}
catch (e) {
e.text = "Error running scripts from content:\n" + e.description;
this.log(e);
}
},
_cacheSetting : function (bindObj, useCache) {
for (var x in this.bindArgs) {
if (dojo.lang.isUndefined(bindObj[x])) {
bindObj[x] = this.bindArgs[x];
}
}
if (dojo.lang.isUndefined(bindObj.useCache)) {
bindObj.useCache = useCache;
}
if (dojo.lang.isUndefined(bindObj.preventCache)) {
bindObj.preventCache = !useCache;
}
if (dojo.lang.isUndefined(bindObj.mimetype)) {
bindObj.mimetype = "text/html";
}
return bindObj;
}
});
@@ -294,7 +294,7 @@ dojo.widget.defineWidget(
},
//from Dojo's ContentPane
//TODO: remove when fixed on Dojo
//TODO: remove when fixed on Dojo (WW-1869)
splitAndFixPaths:function (s, url) {
var titles = [], scripts = [], tmp = [];
var match = [], requires = [], attr = [], styles = [];
File diff suppressed because one or more lines are too long
@@ -22061,6 +22061,7 @@ dojo.widget.defineWidget(
dojo.widget.HtmlWidget, {
widgetType : "Bind",
executeScripts : false,
scriptSeparation : false,
targets : "",
targetsArray : null,
href : "",
@@ -22098,6 +22099,13 @@ dojo.widget.defineWidget(
validate : false,
ajaxAfterValidation : false,
//used for scripts downloading & caching
cacheContent : true,
//run script on its own scope
scriptSeparation : true,
//scope for the cript separation
scriptScope : null,
postCreate : function() {
var self = this;
@@ -22235,14 +22243,7 @@ dojo.widget.defineWidget(
if(this.executeScripts) {
//update targets content
var parsed = this.parse(data);
//eval scripts
if(parsed.scripts && parsed.scripts.length > 0) {
var scripts = "";
for(var i = 0; i < parsed.scripts.length; i++){
scripts += parsed.scripts[i];
}
(new Function('_container_', scripts+'; return this;'))(this);
}
this._executeScripts(parsed.scripts);
this.setContent(parsed.text);
}
else {
@@ -22417,7 +22418,65 @@ dojo.widget.defineWidget(
text: s,
scripts: scripts
};
}
},
//from Dojo content pane
_executeScripts : function (scripts) {
var self = this;
var tmp = "", code = "";
for (var i = 0; i < scripts.length; i++) {
if (scripts[i].path) {
dojo.io.bind(this._cacheSetting({"url":scripts[i].path, "load":function (type, scriptStr) {
dojo.lang.hitch(self, tmp = ";" + scriptStr);
}, "error":function (type, error) {
error.text = type + " downloading remote script";
self._handleDefaults.call(self, error, "onExecError", "debug");
}, "mimetype":"text/plain", "sync":true}, this.cacheContent));
code += tmp;
} else {
code += scripts[i];
}
}
try {
if (this.scriptSeparation) {
delete this.scriptScope;
this.scriptScope = new (new Function("_container_", code + "; return this;"))(self);
} else {
var djg = dojo.global();
if (djg.execScript) {
djg.execScript(code);
} else {
var djd = dojo.doc();
var sc = djd.createElement("script");
sc.appendChild(djd.createTextNode(code));
(this.containerNode || this.domNode).appendChild(sc);
}
}
}
catch (e) {
e.text = "Error running scripts from content:\n" + e.description;
this.log(e);
}
},
_cacheSetting : function (bindObj, useCache) {
for (var x in this.bindArgs) {
if (dojo.lang.isUndefined(bindObj[x])) {
bindObj[x] = this.bindArgs[x];
}
}
if (dojo.lang.isUndefined(bindObj.useCache)) {
bindObj.useCache = useCache;
}
if (dojo.lang.isUndefined(bindObj.preventCache)) {
bindObj.preventCache = !useCache;
}
if (dojo.lang.isUndefined(bindObj.mimetype)) {
bindObj.mimetype = "text/html";
}
return bindObj;
}
});
@@ -22774,7 +22833,7 @@ dojo.widget.defineWidget(
},
//from Dojo's ContentPane
//TODO: remove when fixed on Dojo
//TODO: remove when fixed on Dojo (WW-1869)
splitAndFixPaths:function (s, url) {
var titles = [], scripts = [], tmp = [];
var match = [], requires = [], attr = [], styles = [];
@@ -73,3 +73,6 @@
<#if parameters.highlightDuration?if_exists != "">
highlightDuration="${parameters.highlightDuration?html}"<#rt/>
</#if>
<#if parameters.separateScripts?exists>
scriptSeparation="${parameters.separateScripts?string?html}"<#rt/>
</#if>
@@ -70,6 +70,9 @@
<#else>
"ajaxAfterValidation": false,
</#if>
<#if parameters.separateScripts?exists>
"scriptSeparation": ${parameters.separateScripts?string?html},<#rt/>
</#if>
});
});
</script>
@@ -20,9 +20,6 @@
<#if parameters.refreshOnShow?exists>
refreshOnShow="${parameters.refreshOnShow?string?html}"<#rt/>
</#if>
<#if parameters.separateScripts?exists>
scriptSeparation="${parameters.separateScripts?string?html}"<#rt/>
</#if>
<#if parameters.preload?exists>
preload="${parameters.preload?string?html}"<#rt/>
</#if>
@@ -52,6 +52,7 @@ public class AnchorTest extends AbstractUITagTest {
tag.setHighlightDuration("n");
tag.setValidate("true");
tag.setAjaxAfterValidation("true");
tag.setSeparateScripts("true");
tag.doStartTag();
tag.doEndTag();
@@ -27,6 +27,7 @@ public class BindTest extends AbstractUITagTest {
tag.setHighlightColor("p");
tag.setHighlightDuration("q");
tag.setValidate("true");
tag.setSeparateScripts("true");
tag.doStartTag();
tag.doEndTag();
@@ -48,6 +48,7 @@ public class SubmitAjaxTest extends AbstractUITagTest {
tag.setHighlightDuration("o");
tag.setValidate("true");
tag.setAjaxAfterValidation("true");
tag.setSeparateScripts("true");
tag.setTabindex("1");
tag.doStartTag();
tag.doEndTag();
@@ -77,6 +78,7 @@ public class SubmitAjaxTest extends AbstractUITagTest {
tag.setIndicator("l");
tag.setErrorNotifyTopics("m");
tag.setValidate("true");
tag.setSeparateScripts("true");
tag.setTabindex("1");
tag.doStartTag();
tag.doEndTag();
@@ -107,6 +109,7 @@ public class SubmitAjaxTest extends AbstractUITagTest {
tag.setIndicator("l");
tag.setErrorNotifyTopics("m");
tag.setValidate("true");
tag.setSeparateScripts("true");
tag.doStartTag();
tag.doEndTag();
@@ -20,6 +20,7 @@
"highlightDuration":q,
"validate": true,
"ajaxAfterValidation":false,
"scriptSeparation": true,
});
});
</script>
@@ -7,7 +7,6 @@
startTimerListenTopics="h"
stopTimerListenTopics="i"
refreshOnShow="true"
scriptSeparation="false"
id="mylabel"
href="a"
loadingText="b"
@@ -21,5 +20,6 @@
showError="true"
showLoading="true"
highlightColor="o"
highlightDuration="p">
highlightDuration="p"
scriptSeparation="false">
</div>
@@ -17,5 +17,6 @@
showError="true"
showLoading="true"
highlightColor="m"
highlightDuration="n">
highlightDuration="n"
scriptSeparation="true">
</a>
@@ -21,4 +21,5 @@
showLoading="true"
highlightColor="n"
highlightDuration="o"
scriptSeparation="true"
/>
@@ -15,5 +15,6 @@
errorNotifyTopics="m"
handler="h"
indicator="l"
scriptSeparation="true"
value="i"
/>
@@ -19,4 +19,5 @@
errorNotifyTopics="m"
handler="h"
indicator="l"
scriptSeparation="true"
/>