WW-1536 Add a "cache" property to the head tag, that when true, uses an struts dojo profile, instead of standard dojo profile,

enabling the browser to catch the downloaded javascript files

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@524433 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2007-03-31 14:20:00 +00:00
parent 08b564d52d
commit a4835a7a18
8 changed files with 44649 additions and 6 deletions
@@ -75,6 +75,7 @@ public class Head extends org.apache.struts2.components.Head {
private String baseRelativePath;
private String extraLocales;
private String locale;
private String cache;
public Head(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
@@ -99,6 +100,8 @@ public class Head extends org.apache.struts2.components.Head {
}
if (this.locale != null)
addParameter("locale", findString(this.locale));
if (this.cache != null)
addParameter("cache", findValue(this.cache, Boolean.class));
}
@Override
@@ -116,12 +119,12 @@ public class Head extends org.apache.struts2.components.Head {
return debug != null && Boolean.parseBoolean(debug);
}
@StrutsTagAttribute(description="Set to true to enable Dojo debug messages", defaultValue="false")
@StrutsTagAttribute(description="Enable Dojo debug messages", defaultValue="false", type="Boolean")
public void setDebug(String debug) {
this.debug = debug;
}
@StrutsTagAttribute(description="Use compressed version of dojo.js", defaultValue="true")
@StrutsTagAttribute(description="Use compressed version of dojo.js", defaultValue="true", type="Boolean")
public void setCompressed(String compressed) {
this.compressed = compressed;
}
@@ -140,4 +143,10 @@ public class Head extends org.apache.struts2.components.Head {
public void setLocale(String locale) {
this.locale = locale;
}
@StrutsTagAttribute(description="Use Struts Dojo profile, which contains all Struts widgets in one file, making it possible to be chached by " +
"the browser", defaultValue="true", type="Boolean")
public void setCache(String cache) {
this.cache = cache;
}
}
@@ -41,6 +41,7 @@ public class HeadTag extends AbstractUITag {
private String baseRelativePath;
private String extraLocales;
private String locale;
private String cache;
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new Head(stack, req, res);
@@ -55,6 +56,7 @@ public class HeadTag extends AbstractUITag {
head.setBaseRelativePath(baseRelativePath);
head.setExtraLocales(extraLocales);
head.setLocale(locale);
head.setCache(cache);
}
public void setDebug(String debug) {
@@ -76,4 +78,8 @@ public class HeadTag extends AbstractUITag {
public void setLocale(String locale) {
this.locale = locale;
}
public void setCache(String cache) {
this.cache = cache;
}
}
File diff suppressed because it is too large Load Diff
@@ -3,6 +3,13 @@
djConfig = {
isDebug: ${parameters.debug?default(false)?string},
bindEncoding: "${parameters.encoding}",
<#if parameters.baseRelativePath?if_exists != "">
baseRelativePath: "<@s.url value='${parameters.baseRelativePath}' includeParams='none' encode='false' />",
baseScriptUri: "<@s.url value='${parameters.baseRelativePath}' includeParams='none' encode='false' />",
<#else>
baseRelativePath: "<@s.url value='/struts/dojo/' includeParams='none' encode='false' />",
baseScriptUri: "<@s.url value='/struts/dojo/' includeParams='none' encode='false' />",
</#if>
<#if parameters.locale?if_exists != "">
locale: "${parameters.locale}",
</#if>
@@ -20,14 +27,20 @@
<#assign dojoFile="dojo.js">
<#else>
<#assign dojoFile="dojo.js.uncompressed.js">
</#if>
</#if>
<#if parameters.cache?default(false)>
<#assign profile="struts_">
<#else>
<#assign profile="">
</#if>
<#if parameters.baseRelativePath?if_exists != "">
<script language="JavaScript" type="text/javascript"
src="<@s.url value='${parameters.baseRelativePath}/${dojoFile}' includeParams='none' encode='false' />"></script>
src="<@s.url value='${parameters.baseRelativePath}/${profile}${dojoFile}' includeParams='none' encode='false' />"></script>
<#else>
<script language="JavaScript" type="text/javascript"
src="<@s.url value='/struts/dojo/${dojoFile}' includeParams='none' encode='false' />"></script>
src="<@s.url value='/struts/dojo/${profile}${dojoFile}' includeParams='none' encode='false' />"></script>
</#if>
<script language="JavaScript" type="text/javascript"
@@ -39,9 +39,25 @@ public class HeadTagTest extends AbstractUITagTest {
tag.setExtraLocales("a,b,c");
tag.setBaseRelativePath("/path");
tag.setLocale("es");
tag.setCache("true");
tag.doStartTag();
tag.doEndTag();
verify(HeadTagTest.class.getResource("HeadTagTest-1.txt"));
}
public void testHead2() throws Exception {
HeadTag tag = new HeadTag();
tag.setPageContext(pageContext);
tag.setDebug("false");
tag.setCompressed("true");
tag.setExtraLocales("a,b,c");
tag.setLocale("es");
tag.setCache("false");
tag.doStartTag();
tag.doEndTag();
verify(HeadTagTest.class.getResource("HeadTagTest-2.txt"));
}
}
@@ -3,6 +3,8 @@
djConfig={
isDebug: true,
bindEncoding: "ISO-8859-1",
baseRelativePath: "/path",
baseScriptUri: "/path",
locale: "es",
extraLocale: [
"a",
@@ -12,7 +14,7 @@
};
</script>
<script language="JavaScript" type="text/javascript" src="/path/dojo.js.uncompressed.js">
<script language="JavaScript" type="text/javascript" src="/path/struts_dojo.js.uncompressed.js">
</script>
<script language="JavaScript" type="text/javascript" src="/struts/ajax/dojoRequire.js">
@@ -0,0 +1,24 @@
<script language="JavaScript" type="text/javascript">
// Dojo configuration
djConfig={
isDebug: false,
bindEncoding: "ISO-8859-1",
baseRelativePath: "/struts/dojo/",
baseScriptUri: "/struts/dojo/",
locale: "es",
extraLocale: [
"a",
"b",
"c",
]
};
</script>
<script language="JavaScript" type="text/javascript" src="/struts/dojo/dojo.js">
</script>
<script language="JavaScript" type="text/javascript" src="/struts/ajax/dojoRequire.js">
</script>
<script language="JavaScript" type="text/javascript" src="/struts/CommonFunctions.js">
</script>