正确使用Facelet模板&复合部件 [英] Proper using of Facelet templates & Composite Components

查看:136
本文介绍了正确使用Facelet模板&复合部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然不确定正确使用JSF模板&复合部件。我需要创建一个企业Web应用程序,它将拥有大量页面。每个页面都有相同的标题,菜单,页脚,当然还有不同的内容(= JSF模板)。每个页面上的内容将包含可重复使用的框(= JSF复合组件)。这些盒子包括一些文件,按钮等。我的解决方案是否合适?或者我应该使用其他技术,如自定义组件,装饰......?

I'm still not sure about proper using of JSF Templates & Composite Components. I need create an enterprise web applications, which will have a lot of pages. Every page will have the same header, menu, footer and of course different content (= JSF template). The content on every pages will consist of reusable "boxes" (= JSF composite components). The boxes consist of some fileds, buttons etc. Is my solution proper? Or should I use other technology like , Custom Components, decorate ...?

layout.xhtml

layout.xhtml

<h:body>
    <ui:insert name="main_menu">
        <ui:include src="/xhtml/template/main_menu.xhtml"/>
    </ui:insert>
    <ui:insert name="header">
        <ui:include src="/xhtml/template/header.xhtml"/>
    </ui:insert>
    <ui:insert name="content"/>
    <ui:insert name="footer">
        <ui:include src="/xhtml/template/footer.xhtml"/>
    </ui:insert>
</h:body>

customer_overview.xhtml:

customer_overview.xhtml:

<html xmlns:cc="http://java.sun.com/jsf/composite/composite_component">
<h:body>
    <!-- Facelet template -->
    <ui:composition template="/xhtml/template/layout.xhtml">
        <ui:define name="content">
            <!-- Composite Components -->
            <cc:component_case_history
                caseList="#{customerOverviewController.cases}"
            />
            <cc:component_customer
                ....
            />
            ...
        </ui:define>
    </ui:composition>
</h:body>

component_case_history.xhtml

component_case_history.xhtml

<html xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
    <composite:attribute name="cases" type="java.util.List"/>
</composite:interface>

<composite:implementation>
    <!-- using of "cases" -->
    ...
</composite:implementation>

CustomerOverviewController.java

CustomerOverviewController.java

@ManagedBean
@ViewScoped
public class CustomerOverviewController {
    public List<Case> getCases() {
        ...
    }
}

编辑2012-04-27

基于:
何时使用< ui:include>,标记文件,复合组件和/或自定义组件?

我认为我应该使用Facelet模板+ Facelet标签文件而不是Facelet模板+复合组件。

I think that I should use rather Facelet templates + Facelet tag files instead of Facelet templates + Composite components.

推荐答案

布局,模板



layout.xhtml:



Layout, templating

layout.xhtml:


每个页面都有相同的标题,菜单,页脚......

Every page will have the same header, menu, footer ...

在这种情况下你可以省略ui:插入标题,菜单,页脚的标签。

In this case you can omit the ui:insert tags for header, menu, footer.

<h:body>
    <ui:include src="/xhtml/template/main_menu.xhtml"/>
    <ui:include src="/xhtml/template/header.xhtml"/>
    <ui:insert name="content"/>
    <ui:include src="/xhtml/template/footer.xhtml"/>
</h:body>

你可能还有一个ui:insert没有名字,所以如果你想进一步简化:

You may also have a ui:insert without name, so if you want to further simplify:

<h:body>
    <ui:include src="/xhtml/template/main_menu.xhtml"/>
    <ui:include src="/xhtml/template/header.xhtml"/>
    <ui:insert/>
    <ui:include src="/xhtml/template/footer.xhtml"/>
</h:body>



customer_overview.xhtml:



如果你有ui:在layout.xhtml中没有名字插入,你不需要ui:在这里定义:

customer_overview.xhtml:

If you have ui:insert without name in layout.xhtml, you don't need ui:define here:

<ui:composition template="/xhtml/template/layout.xhtml">
        <!-- Composite Components -->
        <cc:component_customer/>
        <cc:component_case_history
            caseList="#{customerOverviewController.cases}"
        />
        ...
</ui:composition>

此外,您应将模板放在用户无法直接访问的文件夹中(WEB-INF)。

Also you should place your templates in a folder that users cannot access directly (WEB-INF).

您的复合组件之一如下所示:

One of your composite component looks like this:

<cc:component_customer/>

没有任何属性的组件非常可疑。

A component without any attributes is very suspicious.


  • 它做什么?

  • 显示用户名?

  • 如果你没有传递任何属性,它如何获得用户名?

A组件应该是自包含的,对于其他可重用的部件,请使用ui:insert。

A component should be self-contained, for other reusable parts use ui:insert instead.

这篇关于正确使用Facelet模板&amp;复合部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆