- <saf:div ..> tag should be able to not auto start and depend
    make remote connection only when a topic of interest is received



git-svn-id: https://svn.apache.org/repos/asf/struts/action2/trunk@413351 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Toby Jee
2006-06-10 18:50:10 +00:00
parent 5acc1f5e1c
commit f77a41635f
6 changed files with 81 additions and 2 deletions
@@ -7,3 +7,6 @@ struts.custom.i18n.resources=globalMessages
#struts.action.extension=jspa
struts.url.http.port = 8080
struts.freemarker.manager.classname=customFreemarkerManager
struts.serve.static=true
struts.serve.static.browserCache=false
@@ -0,0 +1,27 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="saf" uri="/struts-action" %>
<html>
<head>
<title>Ajax Examples</title>
<jsp:include page="/ajax/commonInclude.jsp"/>
</head>
<body>
<saf:div
id="once"
theme="ajax"
cssStyle="border: 1px solid yellow;"
href="/AjaxTest.action"
updateFreq="0"
delay="0">
Initial Content ... should not change</saf:div>
<saf:include value="../footer.jsp"/>
</body>
</html>
@@ -40,6 +40,10 @@
<li>
<a href="example7.jsp">A div that calls the server, and JS in the resulting page is executed</a>
</li>
<li>
<a href="example8.jsp">A div that will not update itself (updateFreq=0 and delay=0)</a>
</li>
</ol>
@@ -40,6 +40,18 @@ Three Component:
delay="1000">Initial Content</saf:div>
<br/><br/>
Fourth Component:
<saf:div
id="four"
theme="ajax"
cssStyle="border: 1px solid yellow;"
href="/AjaxTest.action"
listenTopics="myLink3_click"
delay="0"
updateFreq="0">Initial Content</saf:div>
<br/><br/>
<saf:url id="remoteLink" value ="/AjaxRemoteLink.action" />
<saf:url id="testLink" value ="/AjaxTest.action" />
@@ -66,7 +78,7 @@ Remote link 2 updating "Two Component" and "Three Component"<br/>
Remote DIV that is not connected to any remote links:
<saf:div
id="four"
id="five"
cssStyle="border: 1px solid yellow;"
href="/AjaxTest.action"
theme="ajax"
@@ -84,6 +96,16 @@ A Remote link that doesn't trigger any remote DIV updates<br/>
</saf:a>
<br/><br/>
A Remote link that will update "Fourth Component"
<saf:a
id="link4"
theme="ajax"
href="%{remoteLink}"
notifyTopics="myLink3_click"
showErrorTransportText="true"
errorText="An Error Ocurred">Update</saf:a>
<br/><br/>
<saf:include value="../footer.jsp"/>
</body>
@@ -18,6 +18,9 @@
package org.apache.struts.action2.components;
import com.opensymphony.xwork.util.OgnlValueStack;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action2.views.util.UrlHelper;
import javax.servlet.http.HttpServletRequest;
@@ -49,6 +52,9 @@ import javax.servlet.http.HttpServletResponse;
* description="Render HTML div providing content from remote call via AJAX"
*/
public class Div extends RemoteCallUIBean {
private static final Log _log = LogFactory.getLog(Div.class);
public static final String TEMPLATE = "div";
public static final String TEMPLATE_CLOSE = "div-close";
@@ -85,6 +91,22 @@ public class Div extends RemoteCallUIBean {
} else {
addParameter("delay", "0");
}
String tmpUpdateFreq = (String) getParameters().get("delay");
String tmpDelay = (String) getParameters().get("updateFreq");
try {
int _updateFreq = Integer.parseInt(tmpUpdateFreq);
int _delay = Integer.parseInt(tmpDelay);
if (_updateFreq <= 0 && _delay <= 0) {
addParameter("autoStart", "false");
}
}
catch(NumberFormatException e) {
// too bad, invalid updateFreq or delay provided, we
// can't determine autoStart mode.
_log.info("error while parsing updateFreq ["+tmpUpdateFreq+"] or delay ["+tmpDelay+"] to integer, cannot determine autoStart mode", e);
}
if (loadingText != null) {
addParameter("loadingText", findString(loadingText));
@@ -10,7 +10,8 @@
<#if parameters.updateFreq?exists>refresh='${parameters.updateFreq}'</#if>
<#if parameters.listenTopics?exists>listenTopics='${parameters.listenTopics}'</#if>
<#if parameters.afterLoading?exists>onLoad='${parameters.afterLoading}'</#if>
<#if parameters.autoStart?exists>autoStart='${parameters.autoStart}'</#if>
<#if parameters.tabindex?exists>
tabindex="${parameters.tabindex?html}"<#rt/>
</#if>