appfuse 样式主题

changNet 2013-08-27

appfuse中web.xml的css样式配置说明:

<!-- Define the default CSS Theme -->
<context-param>
    <param-name>theme</param-name>
    <param-value>simplicity</param-value>
</context-param>

该段用于页面整体风格,theme的值对应相应样式文件夹,appfuse对这个参数的使用如下:

  • 在/myapp/src/web/org/appfuse/webapp/listener/StartupListener.java文件中将theme值放入ServletContext
  • 在/myapp/src/web/org/appfuse/webapp/filter/LocaleFilter.java文件中将request中的theme值保存到ServletContext
  • 页面根据theme值加载css文件

StartupListener.java关键代码

ServletContext context = event.getServletContext();

        // Orion starts Servlets before Listeners, so check if the config
        // object already exists
        Map config = (HashMap) context.getAttribute(Constants.CONFIG);

        if (config == null) {
            config = new HashMap();
        }
        
        if (context.getInitParameter("theme") != null) {
            config.put("theme", context.getInitParameter("theme"));
        }

LocaleFilter.java

String theme = request.getParameter("theme");
        if (theme != null && request.isUserInRole(Constants.ADMIN_ROLE)) {
            Map config = (Map) getServletContext().getAttribute(Constants.CONFIG);
            config.put("theme", theme);
        }

页面根据theme值加载css文件

<link rel="stylesheet" type="text/css" media="all" href="<c:url value='/styles/${appConfig["theme"]}/theme.css'/>" />
 <link rel="stylesheet" type="text/css" media="print" href="<c:url value='/styles/${appConfig["theme"]}/print.css'/>" />

相关推荐

chenyingSunny / 0评论 2011-04-11