首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么<ui:片段rendered>没有在<h:outputStylesheet>和<h:outputScript>上评估

为什么<ui:片段rendered>没有在<h:outputStylesheet>和<h:outputScript>上评估
EN

Stack Overflow用户
提问于 2015-08-26 12:41:53
回答 1查看 1.5K关注 0票数 2

我有一个JSF 2主模板如下所示:

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="#{localeManager.language}" 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">

    <f:view locale="#{localeManager.locale}">
        <h:head>
            <meta charset="UTF-8" />
            <meta http-equiv="X-UA-Compatible" content="IE=edge" />
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            <title><ui:insert name="title">Default Title.</ui:insert></title>

            <!-- Development Stylesheets -->
            <ui:fragment rendered="#{facesContext.application.projectStage eq 'Development'}">
                <h:outputStylesheet name="css/bootstrap.css" library="bootstrap" />
                <h:outputStylesheet name="css/font-awesome.css" library="fontawesome" />
            </ui:fragment>

            <h:outputStylesheet name="css/main.css" library="core" />
            <ui:insert name="header-stylesheet" />

            <!-- Production Stylesheets -->
            <ui:fragment rendered="#{facesContext.application.projectStage eq 'Production'}">
                <h:outputStylesheet name="css/bootstrap.min.css" library="bootstrap" />
                <h:outputStylesheet name="css/font-awesome.min.css" library="fontawesome" />
            </ui:fragment>

            <ui:insert name="header-script" />
        </h:head>

        <h:body>
            <div id="wrapper">
                <div id="header">
                    <ui:insert name="header">Default content</ui:insert>
                </div>

                <div id="body">
                    <ui:insert name="body">Default body</ui:insert>
                </div>

                <div id="footer">
                    <ui:insert name="footer">Default footer</ui:insert>
                </div>
            </div>

            <!-- Development Scripts -->
            <ui:fragment rendered="#{facesContext.application.projectStage eq 'Development'}">
                <h:outputScript name="jquery-2.1.4.js" library="jquery" />
                <h:outputScript name="js/bootstrap.js" library="bootstrap" />
            </ui:fragment>

            <!-- Production Scripts -->
            <ui:fragment rendered="#{facesContext.application.projectStage eq 'Production'}">
                <h:outputScript name="jquery-2.1.4.min.js" library="jquery" />
                <h:outputScript name="js/bootstrap.min.js" library="bootstrap" />
            </ui:fragment>
            <ui:insert name="body-script" />
        </h:body>
    </f:view>
</html>

当将它部署到Wildflix9.0.1Final中时,我看到我的所有<ui:fragment>属性都会被呈现出来。为什么会这样呢?我正在使用JSF2.2框架进行开发。

我的脸项目阶段是Development

注:在所有关于这个问题的答案中,没有一个是这个问题的解决方案(所以我做了我的作业)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-27 07:33:01

<h:outputStylesheet><h:outputScript>是特殊的组件。他们将在视图构建时通过UIViewRoot#addComponentResource() (参见此处的Mojarra源代码)将声明的样式表或脚本资源添加到视图中。

这与组件或其父级的rendered条件无关。实际上,它们基本上被重新定位到<h:head><h:body>的末尾,这取决于target属性的值,从而使它们不再停留在<ui:fragment>中。

然后,在呈现过程中,只考虑它们自己的rendered属性(实际上也考虑<h:head>属性,但这是没有意义的)。

你有两个选择:

  1. 使用视图生成时间标记有条件地将它们添加到视图中。无论如何,项目阶段条件都是应用范围。
  2. 检查组件资源自身的rendered属性中的条件。如果必要的话使用<c:set>来创建一个短的EL变量。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32226974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档