Primefaces 组件不更新

发布于 2025-01-05 21:47:11 字数 2697 浏览 0 评论 0原文

我有 ap:dataGrid,它曾经在 3.0.1 中自我更新。现在我升级到 PF 3.1,“availableIcons”组件的 ajax 更新事件不再触发。我没有收到在视图中找不到该组件的错误。

XHMTL

<h:form id="Application">
......
<p:confirmDialog id="iconDialog" message="Select one icon"
            showEffect="bounce" hideEffect="explode" header="Icon Selection"
            severity="alert" widgetVar="iconSelect" modal="false">

            <p:dataGrid id="availableIcons" var="icon"
                value="#{appEditController.availableIcons}" columns="4">

                <p:column>
                    <p:panel id="pnl" header="" style="text-align:center">
                        <h:panelGrid columns="1" style="width:100%" id="iconPanelGrid">
                            <p:graphicImage value="/resources/icons/#{icon.icon}"
                                id="iconImage" />
                            <p:selectBooleanCheckbox id="iconSelector"
                                value="#{icon.selected}"
                                disabled="#{appEditController.isIconSelected(icon)}">
                                <p:ajax update="availableIcons" event="change"
                                    process="availableIcons"
                                    listener="#{appEditController.iconSelectedChanged(icon)}" />
                            </p:selectBooleanCheckbox>
                        </h:panelGrid>
                    </p:panel>

                </p:column>

            </p:dataGrid>

            <p:commandButton value="Done" update="currentIcon"
                action="#{appEditController.updateCurrentIcon}" ajax="false"
                oncomplete="iconSelect.hide()" />

        </p:confirmDialog>

.......
</h:form>

我没有看到缺少什么或不正确的内容。

支持 bean 代码

public void updateCurrentIcon() {
    for (IconVO iconVO : availableIcons) {
        if (iconVO.isSelected()) {
            log.debug("CURRENT ICON IS NOW " + iconVO.getIcon());

            currentIcon = iconVO;

            break;
        }
    }
}

public void iconSelectedChanged(IconVO iconVO) {


    if (iconVO == currentIcon) {
        log.debug("NULLING ICON");
        currentIcon = null;
    } else {
        log.debug("SETTING NEW ICON");
        currentIcon = iconVO;
    }

}

public boolean isIconSelected(IconVO iconVO) {

    log.debug("IS ICON SELECTED " + iconVO.getIcon());

    if (currentIcon == null
            || iconVO.getIcon().equals(currentIcon.getIcon())) {
        return false;
    }

    return currentIcon != null;
}

这是我尝试执行 update="@form" 的

,然后更新会触发,但会完全关闭模式面板。谢谢, 科恩

I have a p:dataGrid that used to update itself in 3.0.1. Now I upgraded to PF 3.1 and the ajax update event of the "availableIcons" component does not fire anymore. I don't get an error that the component is not found in the view.

The XHMTL

<h:form id="Application">
......
<p:confirmDialog id="iconDialog" message="Select one icon"
            showEffect="bounce" hideEffect="explode" header="Icon Selection"
            severity="alert" widgetVar="iconSelect" modal="false">

            <p:dataGrid id="availableIcons" var="icon"
                value="#{appEditController.availableIcons}" columns="4">

                <p:column>
                    <p:panel id="pnl" header="" style="text-align:center">
                        <h:panelGrid columns="1" style="width:100%" id="iconPanelGrid">
                            <p:graphicImage value="/resources/icons/#{icon.icon}"
                                id="iconImage" />
                            <p:selectBooleanCheckbox id="iconSelector"
                                value="#{icon.selected}"
                                disabled="#{appEditController.isIconSelected(icon)}">
                                <p:ajax update="availableIcons" event="change"
                                    process="availableIcons"
                                    listener="#{appEditController.iconSelectedChanged(icon)}" />
                            </p:selectBooleanCheckbox>
                        </h:panelGrid>
                    </p:panel>

                </p:column>

            </p:dataGrid>

            <p:commandButton value="Done" update="currentIcon"
                action="#{appEditController.updateCurrentIcon}" ajax="false"
                oncomplete="iconSelect.hide()" />

        </p:confirmDialog>

.......
</h:form>

I don't see what's missing or what's incorrect.

This is the backing bean code

public void updateCurrentIcon() {
    for (IconVO iconVO : availableIcons) {
        if (iconVO.isSelected()) {
            log.debug("CURRENT ICON IS NOW " + iconVO.getIcon());

            currentIcon = iconVO;

            break;
        }
    }
}

public void iconSelectedChanged(IconVO iconVO) {


    if (iconVO == currentIcon) {
        log.debug("NULLING ICON");
        currentIcon = null;
    } else {
        log.debug("SETTING NEW ICON");
        currentIcon = iconVO;
    }

}

public boolean isIconSelected(IconVO iconVO) {

    log.debug("IS ICON SELECTED " + iconVO.getIcon());

    if (currentIcon == null
            || iconVO.getIcon().equals(currentIcon.getIcon())) {
        return false;
    }

    return currentIcon != null;
}

I tried to do update="@form", then the update fires but it closes the modal panel completely.

Thanks,
Coen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗笺 2025-01-12 21:47:11

事实上,PrimeFaces 通过相对客户端 ID 定位组件的方式已在 PrimeFaces 3.1 中进行了更改以遵循UIComponent#findComponent() javadoc

在您的特定情况下,您需要指定 绝对客户端 ID。最简单的计算方法是检查生成的 HTML 源中 的 ID。根据目前给出的代码,这将是 Application:availableIcons。您需要在其前面加上 : 前缀以使其绝对,然后在 update 中引用它,如下所示:

<p:ajax update=":Application:availableIcons" ... />

Update as per the comments根本不起作用。您可以尝试将表格包装在一些不可见的包含组件中,例如 并更新它。或者,您可以考虑将 移动到对话框中并使用 update="@form" 代替。无论如何,在对话框之外放置 有点奇怪。您肯定不会提交同一表单内对话框之外的所有其他输入。

Indeed, the way how PrimeFaces locates components by relative client ID has been changed in PrimeFaces 3.1 to adhere the UIComponent#findComponent() javadoc.

In your particular case, you need to specify the absolute client ID of the <p:dataGrid> instead. Easiest way to figure it is to check the ID of the <p:dataGrid> in the generated HTML source. With the code given so far, that would be Application:availableIcons. You need to prefix it with : to make it absolute and then reference it in update as follows:

<p:ajax update=":Application:availableIcons" ... />

Update as per the comments it turns out to not work at all. You could try wrapping the table in some invisible containing component like <h:panelGroup> and update it instead. Alternatively, you could consider moving the <h:form> into the dialog and use update="@form" instead. Having the <h:form> outside the dialog is kind of odd anyway. You surely won't submit all the other inputs which are outside the dialog inside the same form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文