请求范围中的以下属性在哪里? “requestScope.shouldRender”

时间:2012-03-23 19:24:06

标签: java jsf jsf-2

我乞求使用primefaces并在此代码中使用remoteCommand,我看到了#{requestScope.shouldRender}并且我很困惑

<h:form id="form">  

<p:commandButton value="Load" type="button" onclick="lazyload()" id="btnLoad" />  

<p:outputPanel id="lazypanel" layout="block">  
    <h:outputText value="This part of page is lazily loaded on demand using a RemoteCommand"   
            rendered="#{requestScope.shouldRender}"/>  
</p:outputPanel>  

<p:remoteCommand name="lazyload" update="lazypanel">  
    <f:setPropertyActionListener value="#{true}"   
        target="#{requestScope.shouldRender}" />  
</p:remoteCommand>  

我见过与 commandButton remoteCommand 相关的primefaces类,但我没有发现与 shouldRender 相关的任何内容。我有关于requestScope的搜索信息,但我没有找到信息。

如何调用“shouldRender”?是否有更多的属性/方法可以调用相同的方式???

种类问候。

1 个答案:

答案 0 :(得分:3)

#{requestScope}引用请求属性映射,因为您可以通过ExternalContext#getRequestMap()获取(如果您知道基本的Servlet API,则会进一步委托给HttpServletRequest#get/setAttribute()。)

以下一行,

<f:setPropertyActionListener value="#{true}"   
    target="#{requestScope.shouldRender}" /> 

在调用父命令组件时,基本上在当前请求中设置名为“shouldRender”的请求属性和值“true”。

输出文本的呈现属性只是在同一HTTP请求的呈现响应期间拦截:

rendered="#{requestScope.shouldRender}"

总而言之,它只是一种在请求范围内设置属性而无需整个请求范围的辅助bean的方法。它与

实际上有效
<p:outputPanel id="lazypanel" layout="block">  
    <h:outputText value="This part of page is lazily loaded on demand using a RemoteCommand"   
            rendered="#{bean.shouldRender}"/>  
</p:outputPanel>  

<p:remoteCommand name="lazyload" update="lazypanel">  
    <f:setPropertyActionListener value="#{true}"   
        target="#{bean.shouldRender}" />  
</p:remoteCommand>  

@ManagedBean
@RequestScoped
public class Bean {

    private boolean shouldRender;

    // Getter+setter.
}
相关问题