尽管呈现=“假",但是总是评估h:dataTable的内容. [英] Although rendered="false", content of a h:dataTable is always evaluated

查看:91
本文介绍了尽管呈现=“假",但是总是评估h:dataTable的内容.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了JSF 2.0的HtmlDataTable问题.在我的网页上,我有一个h:dataTable和一些其他内容,这些内容仅在用户登录后才能呈现.

I have got a problem with the HtmlDataTable of JSF 2.0. On my web page, i have got a h:dataTable and some other content, which should only be rendered if the user is logged in.

HtmlDataTable的内容是从数据库中加载的.尽管在用户未登录时未呈现h:dataTable,但仍会评估其内容.

The content of the HtmlDataTable is loaded from a database. Although the h:dataTable is not rendered when the user is not logged in, the content is still evaluated.

这是网页的代码:

<h:panelGroup rendered="#{userBean.loggedIn}">
    <h:dataTable value="#{xxxBean.allXxx}"
                 var="c">
        <h:column>
            <h:outputText value="#{c.name}"/>
        </h:column>
    </h:dataTable>
    <!-- some other content -->
</h:panelGroup>

在getAllXxx()方法中,我正在记录该方法的调用.但是,如果未呈现h:dataTable(以及所有其他内容),则仍将调用getAllXxx()方法.

In the getAllXxx() method I am logging the call of the method. But also if the h:dataTable (and all the other content) is not rendered, the getAllXxx() method is still called.

我尝试使用c:if代替h:panelGroup.可以,但是随后在登录过程中出现问题,因此这不是合适的解决方案.

I tried to use c:if instead of the h:panelGroup. That would work, but then I get issues during the login-process, so this is no suitable solution.

有人知道如何解决此问题吗?预先感谢.

Does anyone know how to fix this? Thanks in advance.

推荐答案

使用以下 SSCCE .

test.xhtml

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>SO question 4774516</title>
    </h:head>
    <h:body>
        <h:panelGroup rendered="#{param.show}">
            <h:dataTable value="#{bean.list}" var="item">
                <h:column>#{item}</h:column>
            </h:dataTable>
        </h:panelGroup>
    </h:body>  
</html>

com.example.Bean

package com.example;

import java.util.Arrays;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class Bean {

    private List<String> list = Arrays.asList("one", "two", "three");

    public List<String> getList() {
        System.out.println("getList() called");
        return list;
    }

}

打开 http://localhost:8080/playground/test.jsf 不显示任何标准输出行.打开 http://localhost:8080/playground/test.jsf?show = true 显示它们.

Opening http://localhost:8080/playground/test.jsf doesn't show any stdout lines. Opening http://localhost:8080/playground/test.jsf?show=true shows them.

您的问题是由其他原因引起的.这可能是您的JSF实现中的错误,或者您只是误解了该过程.例如,实际上可以是回发请求,其中,在应用请求值阶段期间调用吸气剂,而#{userBean.loggedIn}的结果仅在调用动作阶段期间进行更改.否则吸气剂会被其他东西调用.

Your problem is caused by something else. Either it's a bug in your JSF implementation or you just misinterpreted the procedure. It can for example actually be a postback request wherein the getter is been called during apply request values phase and the outcome of #{userBean.loggedIn} is only changed during invoke action phase. Or the getter is called by something else.

这篇关于尽管呈现=“假",但是总是评估h:dataTable的内容.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆