尽管 render=“false”,但 ah:dataTable 的内容始终会被评估
我的 JSF 2.0 的 HtmlDataTable 有问题。在我的网页上,我有 ah:dataTable 和一些其他内容,只有在用户登录时才应呈现这些内容。
HtmlDataTable 的内容是从数据库加载的。尽管当用户未登录时不会呈现 h:dataTable,但仍会评估内容。
这是网页的代码:
<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() 方法。
我尝试使用 c:if 而不是 h:panelGroup。这可行,但是我在登录过程中遇到问题,所以这不是合适的解决方案。
有谁知道如何解决这个问题?提前致谢。
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.
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.
Here is the code of the web page:
<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>
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用以下 SSCCE 无法在 Tomcat 7.0.5 上的 Mojarra 2.0.3 上重现您的问题。
test.xhtml
com.example.Bean
打开http: //localhost:8080/playground/test.jsf 不显示任何标准输出行。打开 http://localhost:8080/playground/test.jsf?show=true 向他们展示。
你的问题是由其他原因引起的。这要么是 JSF 实现中的错误,要么是您误解了该过程。例如,它实际上可以是一个回发请求,其中 getter 在应用请求值阶段被调用,而
#{userBean.loggedIn}
的结果仅在调用操作期间更改阶段。或者 getter 被其他东西调用。Can't reproduce your problem on Mojarra 2.0.3 on Tomcat 7.0.5 with the following SSCCE.
test.xhtml
com.example.Bean
Opening http://localhost:8080/playground/test.jsf doesn't show any stdout lines. Opening http://localhost:8080/playground/test.jsf?show=true shows them.
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.