【问题标题】:How can i check if JSF content was defined?如何检查是否定义了 JSF 内容?
【发布时间】:2012-05-16 02:43:19
【问题描述】:

我有这个模板:

<tr>
    <td>
        <ui:insert name="content">Content</ui:insert> 
    </td>
    <td class="rightpanel">
        <ui:insert name="rightpanel">RP</ui:insert> 
    </td>
</tr>

只有当模板客户端定义了右面板内容时,我才想呈现右面板单元格。

【问题讨论】:

  • 保持空白即可。如果模板客户端中定义了某些东西,那么它将替换它,否则它将是空白的(或空白页面)。
  • 但如果 ui 的内容为空白,我不想渲染整个 &lt;td&gt;
  • 如果你希望 是动态的,不要把它放在模板中。在模板客户端中定义它。
  • 我知道这是一个老问题,但如果有人来了,请查看stackoverflow.com/q/5650606/3136474 我在那里找到了更好的解决方案,因为@neni 的答案在我看来是一种解决方法。

标签: templates jsf jakarta-ee facelets


【解决方案1】:

试试这个

模板:

    <!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">

<h:head>
</h:head>

<h:body>
    <tr>
        <td>
            <ui:insert name="content">Content</ui:insert>
        </td>

            <ui:insert name="rightpanel"></ui:insert>

    </tr>
</h:body>
</html>

模板客户端

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:c="http://java.sun.com/jsp/jstl/core">

<h:body>
    <ui:composition template="./TestTemplate.xhtml">

        <ui:define name="content">
               ABCDEF
            </ui:define>
        <ui:define name="rightpanel">
            <h:outputText escape="false" value="<td> ABCD </td>">
            </h:outputText>
        </ui:define>
    </ui:composition>
</h:body>
</html>

我只是使用转义字符来呈现数据。试一试:)

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签