English 中文(简体)
JSF 1.2:我可以在JSF 视图中创建可再使用部分吗?
原标题:JSF 1.2 : Can I create reusable component inside JSF view

在JSF里有这种可能吗?

<ui:composition>
  <x:reusableCode id="editScreen">InnerHtml ... </x:reusableCode>
  code...
  <x:use component="editScreen"/>
</ui:composition

我知道我可以创建我自己的组件 并注册在jsf标签Lib, 但我需要重复使用 HTML 仅在 jsf 视图文件中。

最佳回答

在 Flacelets 1.x 中, 您可以为此创建标签文件 。

创建 /WEB-INF/tags/some.xhtml :

<ui:composition 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
>
    <h:outputText value="#{foo}" />
</ui:composition>

/WEB-INF/my.taglib.xml 中定义:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC
    "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
    "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">

<facelet-taglib>
    <namespace>http://example.com/jsf/facelets</namespace>
    <tag>
        <tag-name>some</tag-name>
        <source>/WEB-INF/tags/some.xhtml</source>
    </tag>
</facelet-taglib>

/WEB-INF/web.xml 中注册:

<context-param>
    <param-name>facelets.LIBRARIES</param-name>
    <param-value>/WEB-INF/my.taglib.xml</param-value>
</context-param>

(注意, 有多个时注意, 使用分号 < code>; 来分离它们)

最后,请在主页模板中声明。

<ui:composition 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:my="http://example.com/jsf/facelets"
>
    <my:some foo="value1" />
    <my:some foo="value2" />
    <my:some foo="value3" />
</ui:composition>

这里可以找到一个更先进的例子: 注:JSF 2.0有针对性,但根据上述例子稍有改动,它对Faceletles 1.x有用。

问题回答

暂无回答




相关问题
JSF a4j:support with h:selectManyCheckbox

I m having trouble with a JSF selectManyCheckbox and A4J support. The purpose is to run some action when a checkbox is selected. This works perfectly in Firefox. Yet, when testing in any IE (ie6 / ie7 ...

Mojarra for JSF Encoding

Can anyone teach me how to use mojarra to encode my JSF files. I downloaded mojarra and expected some kind of jar but what i had downloaded was a folder of files i don t know what to do with

如何拦截要求终止?

在共同基金中,如果用户要求终止,就需要采取一些行动。 我需要某种拦截器,但我不知道如何这样做。 我需要帮助。 增 编

ICEFaces inputFile getting the file content without upload

Is there any way of just getting the content of the browsed file without any upload/file transfer operations? I currently use ICEFaces inputFile component but I do not need the default uploading ...

Weird behaviour of h:commandLink action (MethodExpression)

I have two JSPs where I am displaying some info from database in a h:dataTable. One of them is showing all the info, and one of them user specifically. I have showXML.jsp that shows the "XML" column ...

How to correctly use ResultSet with h:dataTable

The problem is, that after displaying the ResultSet with <h:dataTable>, the connection is left open. If I close it, it closes the ResultSet too. I m thinking about copying the ResultSet data ...