`

jee6 学习笔记 9: Templating and Primefaces Menubar

阅读更多

Templating can reuse some common code. This example discusses the simplest JSF2 templating with facelet tags.

 

To define a template, one can use facelet tag <ui:insert name="title"></ui:insert>. This creates a placeholder to insert real content to generate the final jsf pages. To insert the content, one can use tag <ui:composition/> to wrap the whole page and then use tag <ui:define/> to insert the real stuff.

 

When creating the template, one can use tag <ui:include/> to include common stuff into the template, like a menu bar etc.

 

Here's the simple template used in the example project "/template/template1.xhtml":

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
   	xmlns:ui="http://java.sun.com/jsf/facelets"
   	xmlns:p="http://primefaces.org/ui">

  <h:head>
    <title>
      <ui:insert name="title">Title</ui:insert>
    </title> 
  </h:head>
  
  <h:body>  
     <ui:insert name="menu">
     	<ui:include src="/menubar.xhtml"/>
     </ui:insert>
     
     <p:spacer height="20"/>
     	
     <ui:insert name="content"/>
  </h:body> 
</html>

 

 

Page /tst/testSingleton.xhtml after using the template (template defined in tag "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:p="http://primefaces.org/ui"
   			template="/template/template1.xhtml">

	<ui:define name="title">Test EJB3.1 @Singleton</ui:define>
	
	<ui:define name="content">
		<h:form>
		    <p:panel header="Test EJB3.1 @Singleton" toggleable="true" style="width:60%">
		    	<h:panelGrid columns="1">
		        	Click "Test" to see if it's the same instance:
		        	<h:outputText id="out" value="#{st.message}" escape="false"/>
		        </h:panelGrid>
		        <p:separator/>
		        <p:commandButton value="Test" action="#{st.test}" update="out"/>
		        <p:spacer width="7"/>
		        <p:commandButton value="Clear" actionListener="#{st.reset}" update="out"/>
		    </p:panel>
	    </h:form>
	</ui:define>
</ui:composition>

 

 

Here's the same page before using the template:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:h="http://java.sun.com/jsf/html"
   	xmlns:ui="http://java.sun.com/jsf/facelets"
   	xmlns:p="http://primefaces.org/ui">

	<h:head>
		<title>Test EJB3.1 @Singleton</title>
	</h:head>
	
	<h:body>	
		<h:form>
		    <p:panel header="Test EJB3.1 @Singleton" toggleable="true" style="width:60%">
		    	<h:panelGrid columns="1">
		        	Click "Test" to see if it's the same instance:
		        	<h:outputText id="out" value="#{st.message}" escape="false"/>
		        </h:panelGrid>
		        <p:separator/>
		        <p:commandButton value="Test" action="#{st.test}" update="out"/>
		        <p:spacer width="7"/>
		        <p:commandButton value="Clear" actionListener="#{st.reset}" update="out"/>
		    </p:panel>
	    </h:form>
	</h:body>
</html>

 

 

Here's the Primefaces 3.1 menubar , which is included in the template, "/menubar.xhtml":

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
    
	<h:form>  
	    <p:menubar style="width:60%">  
	        <p:submenu label="Student">  
	        	<p:menuitem value="Search Student" url="/student/studentSearch.jsf" />
	        	<p:menuitem value="New Student" url="/student/studentDetails.jsf" />
	        	<p:separator/>
	        	<p:menuitem value="blah balh" url="#"/>
	        </p:submenu>  
	  
	        <p:submenu label="Test">
	            <p:menuitem value="ajax test" url="/tst/jsfajaxtst.jsf"/>              
	            <p:menuitem value="Get param test" url="/tst/testGetParam.jsf"/>
	            <p:submenu label="ejb test">
		            <p:menuitem value="async ejb test" url="/tst/testAsync.jsf"/>  
		            <p:menuitem value="singleton ejb test" url="/tst/testSingleton.jsf"/>
	            </p:submenu>
	        </p:submenu>  
	  
	        <p:submenu label="Logout">  
	            <p:menuitem value="logout" action="#{loginBean.logout}" />  
	        </p:submenu>  
	    </p:menubar>  
	</h:form>
</html>

 

 

Here's a screen shot of the pages, with the menu bar added:

 


 

 

Next, lets take a look at Internationalization of the web app...

 

  • 大小: 35.7 KB
分享到:
评论

相关推荐

    jee6 学习笔记 6.3 - @Asynchronous

    在Java企业版(Java EE)6中,`@Asynchronous`注解是一个非常重要的特性,它使得开发者可以方便地在应用程序中实现异步处理。这个注解是Java EE并发编程的一部分,主要应用于EJB(Enterprise JavaBeans)环境,用于...

    jee6 学习笔记 1 - 开发环境的配置

    NULL 博文链接:https://jxee.iteye.com/blog/1575432

    jee6 学习笔记 5 - Struggling with JSF2 binding GET params

    这篇"jee6 学习笔记 5 - Struggling with JSF2 binding GET params"主要探讨了开发者在使用JSF2绑定GET参数时可能遇到的挑战和解决方案。 JSF2是一个基于MVC(模型-视图-控制器)设计模式的Java框架,用于创建交互...

    Restlet所需要的所有jar包

    接着,根据你的需求,可以参考Restlet官方文档或者示例代码,学习如何创建和配置`Application`和`Component`,定义路由规则,并处理HTTP请求。 在使用过程中,要注意版本兼容性问题,确保Restlet框架及其依赖库与你...

    JEE企业应用笔记

    ### JEE企业应用笔记 #### 一、JSP与Servlet **JSP (Java Server Pages)** 和 **Servlet** 是Java Web开发中的两个核心组件。它们共同构建了动态Web应用程序的基础。 ##### JSP基本语法 在JSP页面中,可以通过...

    Atlas2.3.0依赖: org.restlet/sqoop-1.4.6.2.3.99.0-195

    在IT行业中,我们经常涉及到各种库和框架的集成与使用,这次我们关注的是"Atlas2.3.0"依赖的组件:"org.restlet/sqoop-1.4.6.2.3.99.0-195"。这个依赖包含了三个关键的JAR文件:`sqoop-1.4.6.2.3.99.0-195.jar`,`...

    JEE6编程模型

    CDI(Contexts and Dependency Injection,上下文和依赖注入)是JEE6中引入的一套全新的依赖注入规范。CDI旨在统一不同组件之间的依赖注入和生命周期管理,支持对Java EE组件的依赖查找和注入操作。CDI通过注解来...

    jee6poc:使用 JEE6 平台的概念证明。 使用 Deltaspike、JSF 和 Primefaces 和 JBoss Logging

    jee6poc 使用 JEE6 平台的概念证明。 它使用 Deltaspike、JSF with Primefaces 和 JBoss Logging。 JBoss 环境设置 概念验证参考环境是 JBoss EAP 6.3GA,需要正确配置 POC 才能按预期工作。 先决条件 安装并配置了...

    jee_paper_checker:h

    【jee_paper_checker:h】项目是一个使用Python编写的工具,主要功能是处理和检查教育考试中的试题和答案。这个工具的目的是帮助教师或教育工作者更有效地管理考试材料,特别是那些包含大量选择题的标准化测试,如...

    JEE_hibernate_test:wakul的属性

    9. **单元测试(Unit Testing)**:在"JEE_hibernate_test"项目中,通常会用到JUnit或其他测试框架来编写针对Hibernate操作的单元测试,确保代码的正确性和稳定性。 10. **集成测试(Integration Testing)**:为了...

    jee6-petclinic2:Spring Pet Clinic 到 JEE 的另一个迁移示例

    jee6-petclinic2 要使用 mysql jndi 资源: 要将 mysql 数据源安装到 Wildfly 8.1 上,请运行“mvn verify -Pds” 在 conf/persistence.xml jta-data-source 和 comment 属性中取消注释。

    JEE-Mains-AnswerKeys:一个自动填充的存储库,其中包含JSON格式的JEE Mains考试的答案键

    JEE-Mains-AnswerKeys:一个自动填充的存储库,其中包含JSON格式的JEE Mains考试的答案键

    JEE-cdi-playgound:JEE CDI 游乐场

    **CDI(Contexts and Dependency Injection)是Java企业版(JEE)中的一项核心技术,它为Java应用程序提供了依赖注入(DI)的功能。在“JEE-cdi-playgound: JEE CDI 游乐场”项目中,我们可以通过实践来深入理解CDI...

    jee 入门(深入浅出学习JEE)

    【JEE入门(深入浅出学习JEE)】 Java企业版(Java Enterprise Edition,简称JEE),也称为Java EE,是Oracle公司推出的企业级应用程序开发平台。它为开发分布式、多层架构的Web应用程序提供了全面的框架和服务。JEE...

    org.restlet-2.3.0.jar 最新版本

    6. **扩展性**:提供了丰富的扩展点,可以方便地添加自定义处理器、过滤器和组件,满足特定业务需求。 7. **文档和社区支持**:官方文档详尽且更新及时,社区活跃,遇到问题时能得到及时的帮助。 在实际应用中,...

    jee6 学习系列告一段落,uploaded zipped project after JAAS security

    标题中的“JEE6 学习系列告一段落,uploaded zipped project after JAAS security”表明这是一个关于Java Enterprise Edition(JEE)6的项目,特别关注了Java Authentication and Authorization Service (JAAS)的...

    JEE_Struts_test:wakul的属性

    在Java企业级开发中,Struts框架是一个非常重要的部分,它属于MVC(Model-View-Controller)设计模式的一种实现,极大地简化了Web应用的开发。...深入研究这个项目,可以更好地理解和学习Java EE和Struts框架的应用。

    bee-jee-test-task:MVC简单应用

    6. **Vendor**(如果使用Composer管理依赖):存储第三方库和框架核心组件。 完成这个“bee-jee-test-task”将使开发者掌握PHP MVC框架的基本工作流程,包括如何组织代码、如何处理请求和响应、以及如何使用模型...

    JSF+primefaces 网盘实现代码前端

    PrimeFaces是一个流行的Java库,提供了丰富的UI组件,使得开发高质量的Web应用程序变得更加便捷。 首先,JSF是一个用于构建MVC(模型-视图-控制器)结构的Java EE框架,它允许开发者创建动态、交互式的Web应用。JSF...

    jee-simple-crud:Java EE 类的第一个项目

    【标题】"jee-simple-crud:Java EE 类的第一个项目"是一个初学者导向的教程,旨在帮助开发者构建他们的第一个Java EE应用程序。这个项目的核心是实现基本的CRUD(创建、读取、更新、删除)操作,这是任何Web应用程序...

Global site tag (gtag.js) - Google Analytics