//index.jsp
theme测试
<a href="theme.action">go</a>
//theme.jsp
在struts.xml中控制theme,默认为xhtml,可以设置为:simple/css_html/ajax
<br/>
要看页面源码
<ol>
<li>
<s:form> <!-- formFieldError 默认带一个小点 -->
<div class="formFieldError">
<s:fielderror /> <!-- 取出放入的对应校验错误 -->
</div>
<s:textfield name='aaa'></s:textfield>
</s:form>
</li>
</ol>
//theme1.jsp
<style type="text/css">
.formFieldError {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 12px;
color: #FF3300;
vertical-align: bottom;
}
.formFieldError ul { /*list-style-type: none*/
margin: 0px;
padding: 3px;
vertical-align: middle;
}
.formFieldError ul li {
/* 默认带了 ul li,重写ul li覆盖了原来的,去掉了小点,
也可以重写或定义自己simple主题,覆盖原来的 */
list-style-type: none
}
</style>
用CSS控制显示
<br/>
要看页面源码
<ol>
<li>
<s:form><!-- 去掉了默认带的小点 -->
<div class="formFieldError">
<s:fielderror />
</div>
<s:textfield name='aaa'></s:textfield>
</s:form>
</li>
</ol>
//struts.xml
<constant name="struts.i18n.encoding" value="GBK" /> <!-- internationalization -->
<constant name="struts.ui.theme" value="css_xhtml" /><!--
<constant name="struts.ui.theme" value="mytheme" /> --><!-- 定义自己的主题 -->
<package name="theme" extends="struts-default" namespace="/">
<action name="theme" class="com.bjsxt.struts2.theme.ThemeAction">
<result>/theme.jsp</result>
</action>
</package>
//action
package com.bjsxt.struts2.theme;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class ThemeAction extends ActionSupport {
public String execute() { //添加校验错误信息
this.addFieldError("fielderror.test", "wrong!");
return SUCCESS;
}
}