在RichFaces中使用Facelets模板
在RichFaces中使用Facelets模板
Facelets简介
Facelets是用来构建JSF应用程序的默认视图技术。它为表现层提供了一个强有力的模板化系统。这里将简单介绍一下如何在RichFaces中使用Facelets模板标签。开发环境是基于Maven的,至于如何在Maven中构建RichFaces项目,详情可以参考这里。
Facelets标签
下面表格中列举的是模板技术要使用到的标签:
标签 | 说明 |
---|---|
ui:include |
包含另一个文件中的内容。 |
ui:composition |
如果不使用 template 属性,组合是一连串可插入到其它地方的元素。组合可以具有可变部分(使用 ui:insert 子标签指定)。如果使用 template 属性,则加载该模板。 |
ui:define |
定义了匹配 ui:insert 插入到模板中的内容。 |
ui:insert |
将内容插入到模板 |
创建相应文件
下图是示例的最终结构
在 faces-config.xml
中添加资源文件 messages.properties
。
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<resource-bundle>
<base-name>messages</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
indexTitle=Index Page
indexContent=Welcome to RichFaces
tabTitle=Tab Panel Page
colTitle=Collapsible Panel Page
header=RichFaces Demo
模板文件 mainLayout.xhtml
。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view>
<h:head>
<title><ui:insert name="pageTitle"/></title>
<!-- 模板布局css文件 -->
<h:outputStylesheet library="css" name="layout.css"/>
</h:head>
<h:body>
<div class="body">
<!-- 页眉 -->
<div class="header">
<ui:insert name="header">
<ui:include src="header.xhtml"/>
</ui:insert>
</div>
<div class="main">
<!-- 侧边栏 -->
<div class="menu">
<ui:insert name="menu">
<ui:include src="menu.xhtml"/>
</ui:insert>
</div>
<div class="content">
<ui:insert name="content"/>
</div>
</div>
</div>
</h:body>
</f:view>
</ui:composition>
然后是页面共用的页眉 header.xhtml
和侧边栏 menu.xhtml
文件。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:form>
#{msg.header}
</h:form>
</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:form>
<rich:panelMenu>
<rich:panelMenuGroup label="panels" expanded="true">
<rich:panelMenuItem>
<h:commandLink action="tabPanel" value="Tab Panel"/>
</rich:panelMenuItem>
<rich:panelMenuItem>
<h:commandLink action="colPanel" value="Collapisible Panel"/>
</rich:panelMenuItem>
</rich:panelMenuGroup>
</rich:panelMenu>
</h:form>
</ui:composition>
最后是拥有具体内容的三个文件 index.xhtml
, tabPanel.xhtml
, colPanel.xhtml
。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="/templates/mainLayout.xhtml">
<!-- ui:define标签对应于模板文件中的ui:insert标签 -->
<ui:define name="pageTitle">#{msg.indexTitle}</ui:define>
<ui:define name="content">
<rich:panel header="Main">
#{msg.indexContent}
</rich:panel>
</ui:define>
</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="/templates/mainLayout.xhtml">
<!-- ui:define标签对应于模板文件中的ui:insert标签 -->
<ui:define name="pageTitle">#{msg.tabTitle}</ui:define>
<ui:define name="content">
<h:form>
<rich:tabPanel switchType="client">
<rich:tab header="Tab One">
this is tab one
</rich:tab>
<rich:tab header="Tab Two">
this is tab two
</rich:tab>
</rich:tabPanel>
</h:form>
</ui:define>
</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="/templates/mainLayout.xhtml">
<!-- ui:define标签对应于模板文件中的ui:insert标签 -->
<ui:define name="pageTitle">#{msg.colTitle}</ui:define>
<ui:define name="content">
<h:form>
<rich:collapsiblePanel header="Collapsible Panel" switchType="client">
this is collapsible panel
</rich:collapsiblePanel>
</h:form>
</ui:define>
</ui:composition>
这样,Facelets通过模板技术将页面的公共部分同具体内容相互区分开来,示例的最终效果如下:
在RichFaces中使用Facelets模板的更多相关文章
- VS2013中的MVC5模板部署到mono上的艰辛历程
部署环境:CentOS7 + Mono 3.10 + Jexus 5.6 在Xamarin.Studio创建的asp.net项目,部署过程非常顺利,没有遇到什么问题:但在VS2013中创建的asp.n ...
- VS2012中丢失ArcGIS模板的解决方法
VS2012中丢失ArcGIS模板的解决方法 由于ArcGIS10.0(for .NET)默认是用VS2010作为开发工具的,所以在先安装VS2012后装ArcGIS10.0 桌面版及ArcObjec ...
- Win 10 开发中Adaptive磁贴模板的XML文档结构,Win10 应用开发中自适应Toast通知的XML文档结构
分享两篇Win 10应用开发的XML文档结构:Win 10 开发中Adaptive磁贴模板的XML文档结构,Win10 应用开发中自适应Toast通知的XML文档结构. Win 10 开发中Adapt ...
- 在express站点中使用ejs模板引擎
在express站点中使用ejs模板引擎 文/玄魂 目录 在express站点中使用ejs模板引擎 前言 1.1 安装 1.2修改app.js 1.3创建测试页面 前言 使用 vs创建 ...
- WPF 中获取DataGrid 模板列中控件的对像
WPF 中获取DataGrid 模板列中控件的对像 #region 当前选定行的TextBox获得焦点 /// <summary> /// 当前选定行的TextBox获得焦点 /// &l ...
- Django中如何查找模板
参考:http://my.oschina.net/zuoan001/blog/188782 Django的setting中有关找模板的配置有如下两个: TEMPLATE_LOADERS TEMPLAT ...
- ArcGIS API for Silverlight代码中使用Template模板
原文:ArcGIS API for Silverlight代码中使用Template模板 在项目开发中,会遇到点选中聚焦闪烁效果,但是因为在使用Symbol的时候,会设置一定的OffSetX和OffS ...
- 在VS中使用类模板出现出现LNK2019: 无法解析的外部符号错误。
在VS中使用类模板出现出现LNK2019: 无法解析的外部符号错误,应在一个.h文件中完成方法的声明与实现,不要将实现放在cpp文件里,VS貌似不支持类模板分离
- WPF中的数据模板(DataTemplate)(转)
原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/30/694388.html WPF中的数据模板(DataTemplate) ...
随机推荐
- Storm入门3-集群搭建
[storm集群的搭建以及将开发好的拓扑提交到集群上运行的方法] 在上一篇文章中,我们的拓扑直接运行,并在程序开始时候自动启动一个本地"集群"来运行拓扑.LocalCluster这 ...
- Redis缓存连接池管理
import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.util.Assert;import ...
- windows页面打印div(弹出新页面)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- Jquery中each的三种遍历方法
Jquery中each的三种遍历方法 $.post("urladdr", { "data" : "data" }, function(dat ...
- Android4.0.3 USB OTG底层插入上报过程分析(1)
下面的两个宏是PM8058的MMP11(R15),MMP12(P15)管脚.#define EXT_CHG_VALID_MPP 10#define EXT_CHG_VALID_MPP_2 11 sta ...
- 让Xcode 8.x能够调试iOS 7.x真机
首先需要 Xcode 7.x.可以去 苹果开发者官网 下载. 打开Finder, 进入文件夹: Xcode .x.app/Contents/Developer/Platforms/iPhoneOS.p ...
- java基本数据类型的字面量
java的基本数据类型一共有8种.其中:(每种类型后面列出了java中的该类型的字面量) 四种整型: int 4字节: 12 +12 -12 077 0xFF 0b101(JDK7中支持的二 ...
- 使用phpmailer发送smtp邮件时提示 SMTP Error: Could not authenticate 错误
使用phpmailer发送smtp邮件时提示 SMTP Error: Could not authenticate 错误 这个错误是验证出现错误, $mail->Port = 25; //SMT ...
- angularjs 的笔记
angular.copy()深拷贝 angular提供了一个可以复制对象的api--copy(source,destination),它会对source对象执行深拷贝. 使用时需要注意下面几点: 如果 ...
- Android中实现全屏、无标题栏的两种办法
在进行UI设计时,我们经常需要将屏幕设置成无标题栏或者全屏.要实现起来也非常简单,主要有两种方法:配置xml文件和编写代码设置. 1.在xml文件中进行配置 在项目的清单文件AndroidManife ...