且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将JSF标记与JSTL标记混合会产生奇怪的结果

更新时间:2022-06-14 16:12:23

JSF和JSTL没有按照您对编码的期望同步运行。 JSTL在视图的构建期间运行(当要填充JSF组件树时),并且JSF在视图组件树的渲染时间期间运行(当要生成HTML输出时)。您可以按如下方式对其进行可视化:JSTL首先从上到下运行,然后将结果移交给JSF,JSF又从上到下再次运行。

JSF and JSTL doesn't run in sync as you'd expect from the coding. JSTL runs during build time of the view (when the JSF component tree is to be populated) and JSF runs during render time of the view component tree (when HTML output is to be generated). You can visualize it as follows: JSTL runs first from top to bottom and then hands over the result to JSF which in turn runs from top to bottom again.

在您的特定情况下,JSTL中永远不会出现对象 instance

In your particular case, the object instance is never present in JSTL.

而不是 c:forEach ,你应该使用 ui:repeat 而不是 c:如果您应该使用JSF组件的呈现的属性。我想重写代码,但 hideTypes 的使用是一团糟。而是将其转换为模型中的 List< String> ,并且使用纯JSF会更容易。这是一个启动示例,假设 hideTypes 列表< String>

Instead of c:forEach, you should use ui:repeat and instead of c:if you should use JSF component's rendered attribute. I'd like to give a rewrite of the code, but the usage of hideTypes is a mess. Rather convert it to a List<String> in the model and it'll be much easier to do with pure JSF. Here's a kickoff example assuming that hideTypes is a List<String>:

<h:panelGroup rendered="#{not empty hideTypes}">
    <ui:repeat value="#{document.instanceList}" var="instance">
        <a:outputPanel rendered="#{!hideTypes.contains(instance.documentInstanceType.mimeType)}">
            <up:mimeTypeIcon type="#{instance.documentInstanceType.mimeType}"
                icon="#{instance.documentInstanceType.iconPath}"
                key="#{instance.instanceKey}" referenced="false"/>
        </a:outputPanel>
     </ui:repeat>
<h:panelGroup>