WebWork2.2.2中一个控件的theme的查找顺序

[url=http://www.jscud.com/srun/news/viewhtml/4_2006_3/182.htm]WebWork2.2.2中一个控件的theme的查找顺序[/url]

webwork 2.2.2中提供了几个theme,包括simple,xhtml以及新的ajax,css_xhtml等等.

每个控件都可以指定theme,那么theme是什么查找顺序哪?都由什么因素控制哪?

让我们来看UIBean中的一段代码:


public String getTheme() {
String theme = null;

if (this.theme != null) {
theme = findString(this.theme);
}

if ( theme == null || theme.equals("") ) {
Form form = (Form) findAncestor(Form.class);
if (form != null) {
theme = form.getTheme();
}
}

// If theme set is not explicitly given,
// try to find attribute which states the theme set to use
if ((theme == null) || (theme.equals(""))) {
theme = (String) stack.findValue("#attr.theme");
}

// Default theme set
if ((theme == null) || (theme.equals(""))) {
theme = Configuration.getString(WebWorkConstants.WEBWORK_UI_THEME);
}

return theme;
}




可以看到,顺序是这样的:

首先查找控件本身的theme,也就是说控件本身可以设定theme
如果没有找到,则查找此控件所在的form的theme,如果找到了,就使用form的theme设定
如果还没有找到,则在value stack里查找属性theme. 也就是说你可以编程控制theme设定
如果最后还没有找到,则到配置文件里寻找,默认的是xhtml,用户可以在webwork.properties里面修改配置
这样你就可以在各个环节进行设置,达到自己的目的.

其中attr的说明参考 http://wiki.opensymphony.com/display/WW/Accessing+application%2C+session%2C+request+objects 以及 http://wiki.opensymphony.com/display/WW/What+are+the+default+variables+in+the+value+stack

attr: 会依次扫描 request, session 和 application attributes 设置
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值