简体   繁体   English

渲染在Primefaces5 + JSF2中不起作用

[英]rendered not working in Primefaces5+JSF2

Here my XHTML code 这是我的XHTML代码

<p:selectOneRadio id="selectone"
                    value="#{tweetDistributionManagedBean.tweetType}">
                    <f:selectItem itemLabel="Group Tweets" itemValue="GT" />
                    <f:selectItem itemLabel="Event Tweets" itemValue="ET" />
                    <f:selectItem itemLabel="Suprachar Tweets" itemValue="ST" />
                    <p:ajax event="click"
                        listener="#{tweetDistributionManagedBean.renderUploadPanel}"
                        update="gtid" process="@form" />
                </p:selectOneRadio>

and Java method i am calling 和我正在调用的Java方法

public void renderUploadPanel(AjaxBehaviorEvent event) {
       // String selecteValues = (String) event. ;
        visibleGTFlag = true;
        System.out.println("Method called----------->"+visibleGTFlag);
    }

And i want to rendred this panel when a checkbox is clicked 我想在单击复选框时重新显示此面板

<p:panel id="gtid"
                rendered="#{tweetDistributionManagedBean.visibleGTFlag}"
                toggleable="true">
                <p:fileUpload
                    fileUploadListener="#{tweetDistributionManagedBean.handleFileUpload}"
                    mode="advanced" multiple="true" update="messages" auto="true"
                    sizeLimit="1048576" allowTypes="/(\.|\/)(doc|docx|xls|xlsx|pdf)$/" />
            </p:panel>

But when i am refreshing this page then this panel rendering what i am doing wrong? 但是,当我刷新此页面时,此面板呈现了我做错的事情?

The problem is that when a component has rendered="false" it won't be added in the view tree component, so it cannot be referenced nor updated by any component in the current view. 问题在于,当一个组件rendered="false" ,它将不会被添加到视图树组件中,因此当前视图中的任何组件都无法引用或更新它。 This explains why this update fails when you try to update the component by an ajax request, because you're still in the same view, while when you fire a complete request on the page you can see the component, because it is a new view. 这解释了为什么当您尝试通过ajax请求更新组件时此更新失败,因为您仍处于同一视图中,而当您在页面上触发完整请求时,您可以看到该组件,因为它是一个新视图。

The solution for these problems is to wrap the non-rendered component inside a UIContainer and update the wrapper component instead. 这些问题的解决方案是将未渲染的组件包装在UIContainer中,并更新包装器组件。 You may use <h:panelGroup layout="block"> that will render as a HTML div: 您可以使用<h:panelGroup layout="block">将其呈现为HTML div:

<p:selectOneRadio id="selectone"
    value="#{tweetDistributionManagedBean.tweetType}">
    <f:selectItem itemLabel="Group Tweets" itemValue="GT" />
    <f:selectItem itemLabel="Event Tweets" itemValue="ET" />
    <f:selectItem itemLabel="Suprachar Tweets" itemValue="ST" />
    <p:ajax event="click"
        listener="#{tweetDistributionManagedBean.renderUploadPanel}"
        update="gtidWrapper" process="@form" />
</p:selectOneRadio>

<!-- rest of Facelets code... -->

<h:panelGrid id="gtidWrapper" layout="block">
    <p:panel id="gtid"
        rendered="#{tweetDistributionManagedBean.visibleGTFlag}"
        toggleable="true">
        <p:fileUpload
            fileUploadListener="#{tweetDistributionManagedBean.handleFileUpload}"
            mode="advanced" multiple="true" update="messages" auto="true"
            sizeLimit="1048576" allowTypes="/(\.|\/)(doc|docx|xls|xlsx|pdf)$/" />
    </p:panel>
</h:panelGrid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM