Jsf 为什么<;ui:渲染片段>;未在<;h:outputStylesheet>;及<;h:outputScript>;
我有一个JSF 2主模板,如下所示:Jsf 为什么<;ui:渲染片段>;未在<;h:outputStylesheet>;及<;h:outputScript>;,jsf,jsf-2,facelets,conditional-rendering,Jsf,Jsf 2,Facelets,Conditional Rendering,我有一个JSF 2主模板,如下所示: <!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/j
<!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>
默认标题。
默认内容
默认主体
默认页脚
在Wildfly 9.0.1 Final中部署它时,我看到所有的
属性都被渲染。为什么呢?我正在使用JSF2.2框架进行开发
我的Faces项目阶段是开发
注:在SO中关于这个问题的所有答案中,没有一个是这个问题的解决方案(因此我做了家庭作业)。和是特殊组件。他们将在视图构建期间通过()将声明的样式表或脚本资源添加到视图中
这与组件或其父级的渲染状态无关。实际上,它们基本上被重新定位到
或
的最末端,具体取决于target
属性的值,从而使它们不再位于
内部
然后,在渲染过程中,只考虑它们自己的rendered
属性(实际上也是
,但这是毫无意义的)
您有两种选择:
使用视图生成时间标记有条件地将它们添加到视图中。无论如何,项目阶段条件的应用范围是有限的
<!-- Development Stylesheets -->
<c:if test="#{facesContext.application.projectStage eq 'Development'}">
<h:outputStylesheet ... />
<h:outputStylesheet ... />
</c:if>
<!-- Production Stylesheets -->
<c:if test="#{facesContext.application.projectStage eq 'Production'}">
<h:outputStylesheet ... />
<h:outputStylesheet ... />
</c:if>
因此,如果我使用JSTL conditionalif
,我是否应该使用$
而不是#
?您可以,但这不是统一的,对初学者来说是不必要的混淆。在Facelets中,${}
的行为与{}
完全相同,但在JSP中,${}
会立即(“静态”)进行计算,而{}
只会在每次调用时(“延迟”)进行计算。谢谢。我得到了使用JSTL conditionalif
的东西。也谢谢你,我花了几个小时检查为什么我的ui:fragment
及其周围的呈现属性不起作用。
<c:set var="dev" value="#{facesContext.application.projectStage eq 'Development'}" scope="application" />
<!-- Development Stylesheets -->
<h:outputStylesheet ... rendered="#{dev}" />
<h:outputStylesheet ... rendered="#{dev}" />
<!-- Production Stylesheets -->
<h:outputStylesheet ... rendered="#{not dev}" />
<h:outputStylesheet ... rendered="#{not dev}" />