http://blog.csdn.net/struts2/archive/2007/08/03/1724395.aspx
-------------------example8.jsp好看--------------------
public class MergeIteratorTagDemo extends ActionSupport implements Validateable 自动validate
实现这个接口,com.opensymphony.xwork2.Validateable,error自动绑定到该字段下。
public void validate() {
if (iteratorValue1 == null || iteratorValue1.trim().length() <= 0 ) {
addFieldError("iteratorValue1", "iterator value 1 cannot be empty");
}
else if (iteratorValue1.trim().indexOf(",") <= 0) {
addFieldError("iteratorValue1", "iterator value 1 needs to be comma separated");
}
}
页面: <s:form action="submitMergeTagDemo" namespace="/tags/non-ui/mergeIteratorTag" method="POST">
<s:textfield label="Iterator 1 Value (Comma Separated)" name="iteratorValue1" />
<s:textfield label="Iterator 2 Value (Comma Separated)" name="iteratorValue2" />
<s:submit />
</s:form>
(7)
<s:select label="label" name="name"
list="{'name1','name2','name3'}" value="%{'name2'}" /> 默认为name2
这样将_A的模板放在一起叫做A主题(Theme),将_B的模板放在一起叫B主题。这样我们在分别使用A主题,B主题的时候可以得到同一个Tag的不同的视觉效果。
模版和主题的概念处在Struts Tag的核心位置。
Struts2默认提供了四种主题:
Simple 主题:最简单的主题
XHTML 主题:默认主题,使用常用的HTML技巧
CSS XHTML主题: 使用CSS实现的XHTML主题
AJAX 主题:基于XHTML主题,但是同工了AJAX功能
相关配置:
在struts.properties文件中有如下项目:
struts.ui.theme=xhtml
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).??
出现这个问题,可能是添加了struts2-codebehind包,去除这个包就可以了.
(8)<s:url var="ajaxTest" value="/AjaxTest.action" />
<s:a href="%{ajaxTest}">
(9)<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<sx:head cache="true"/>
<s:url var="ajaxTest" value="/AjaxTest.action" />
<sx:div
cssStyle="border: 1px solid yellow;"
href="%{ajaxTest}">
Initial Content</sx:div>
<sx:div>需要<sx:head cache="true">
这个div会一开始显示Initial Content ,然后再请求action.把div的内容给换掉。
(10) <sx:div
id="once"
cssStyle="border: 1px solid yellow;"
href="%{#ajaxTest}"
updateFreq="2000"
indicator="indicator"
>
Initial Content</sx:div>
<img id="indicator" src="${pageContext.request.contextPath}/images/indicator.gif" alt="Loading..." style="display:none"/>
这个是每2秒请求一次action,并且显示indicator.gir.只是闪一下就看不见了。
delay="2000"
errorText="There was an error" 没有找到url
loadingText="reloading"
showLoadingText="true" 这两个是一块用的。
showErrorTransportText="true" 页面没有找url,页面显示为Error loading '/AjaxNoUrl.jsp' (404 Not Found)
handler="handler" "handler"和下面的function对应
<script type="text/javascript">
function handler(widget, node) {
alert('I will handle this myself!');
node.innerHTML = "Done";
}
</script>
(11)
<script>
var controller = {
refresh : function() {},
start : function() {},
stop : function() {}
};
dojo.event.topic.registerPublisher("/refresh", controller, "refresh");
dojo.event.topic.registerPublisher("/startTimer", controller, "start");
dojo.event.topic.registerPublisher("/stopTimer", controller, "stop");
</script>
<form id="form">
<label for="textInput">Text to be echoed</label>
<input type=textbox id="textInput" name="data">
</form>
<br/><br/>
<input type=button value="refresh" οnclick="controller.refresh()">
<input type=button value="stop timer" οnclick="controller.stop()">
<input type=button value="start timer" οnclick="controller.start()">
<s:url var="ajaxTest" value="/AjaxTest.action" />
<sx:div
id="once"
cssStyle="border: 1px solid yellow;"
href="%{ajaxTest}"
loadingText="Loading..."
listenTopics="/refresh"
startTimerListenTopics="/startTimer"
stopTimerListenTopics="/stopTimer"
updateFreq="3000"
autoStart="true"
highlightColor="red"
formId="form"
>
Initial Content</sx:div>
-----------------------
beforeNotifyTopics="/before"
afterNotifyTopics="/after"
dojo.event.topic.subscribe("/before", function(data, type, e){
alert('inside a topic event. before request');
//data : source element id
//type : "before"
//e : request object
});
dojo.event.topic.subscribe("/after", function(data, type, e){
alert('inside a topic event. after request');
//data : text returned
//type : "load"
//e : undefined
});
和(11)合在一起,它可以在一个请求前后,执行一些代码。