重新渲染丰富的部分:popupPanel

Posted

技术标签:

【中文标题】重新渲染丰富的部分:popupPanel【英文标题】:rerender part of rich:popupPanel 【发布时间】:2012-11-17 02:19:18 【问题描述】:

我正在合作:

- RichFaces 4.2.2
- Mojarra 2.1.14

让我们看看下面的简单代码:

<h:form>
    <h:selectOneRadio value="#testBean.option" >
        <f:selectItem itemValue="0" itemLabel="Option 0"/>
        <f:selectItem itemValue="1" itemLabel="Option 1"/>
        <f:ajax execute="@this" render="infoPanelId"/>
    </h:selectOneRadio>
    <a4j:outputPanel id="infoPanelId">
        <h:outputText value="Option 0 selected" rendered="#testBean.option == '0'"/>
        <h:outputText value="Option 1 selected" rendered="#testBean.option == '1'"/>
    </a4j:outputPanel>
</h:form>

和 bean 代码:

@ManagedBean(name="testBean")
@ViewScoped
public class TestBean implements Serializable

    private String option;

    public String getOption() 
        return option;
    

    public void setOption(String option) 
        this.option = option;
    

它工作得很好,而且很简单。重新渲染按预期工作。 但是如果我们把这个简单的代码放在 rich:popupPanel 标记中,那段代码就不起作用了。 这是代码sn-p:

<h:form>
    <a4j:commandButton 
        value="show popup" 
        oncomplete="#rich:component('testPopup').show()"
        render="testPopup"
    />

    <rich:popupPanel id="testPopup" modal="false" autosized="true" resizable="false">
        <f:facet name="header">
            <h:outputText value="popup"/>
        </f:facet>
        <h:panelGrid columns="1">
            <h:selectOneRadio value="#testBean.option" >
                <f:selectItem itemValue="0" itemLabel="Option 0"/>
                <f:selectItem itemValue="1" itemLabel="Option 1"/>
                <f:ajax execute="@this" render="infoPanelId"/>
            </h:selectOneRadio>
        <a4j:outputPanel id="infoPanelId">
                <h:outputText value="Option 0 selected" rendered="#testBean.option == '0'"/>
                <h:outputText value="Option 1 selected" rendered="#testBean.option == '1'"/>
            </a4j:outputPanel>
        </h:panelGrid>
    </rich:popupPanel>
</h:form>

所以popupPanel里面的代码不起作用。我无法重新渲染 popupPanel 的一部分。所以我有两个问题:

    为什么? 我怎样才能让它工作?

【问题讨论】:

【参考方案1】:

1) 因为默认情况下popupPanel 显示在&lt;body&gt; 元素内

2) 将domElementAttachment="form" 添加到rich:popupPanel 应该会有所帮助

【讨论】:

谢谢弗拉基米尔!你是对的,domElementAttachment 可以解决问题。

以上是关于重新渲染丰富的部分:popupPanel的主要内容,如果未能解决你的问题,请参考以下文章

vue 监听窗口变化对页面部分元素重新渲染

项目更改时反应本机部分列表不重新渲染

内联 Javascript 在 Rails 3.1 上重新渲染部分 ruby​​ 时无法正常工作

在 js.erb 中渲染 Rails 部分而不重新加载整个页面

使用 LWJGL 对 GUI 进行部分渲染 [关闭]

Rails Ajax - 渲染不同的部分