在f:facet name =“ header”中更新Primefaces数据表。不工作 [英] Primefaces datatable update in f:facet name="header" not working

查看:80
本文介绍了在f:facet name =“ header”中更新Primefaces数据表。不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新primefaces数据表的表头中的按钮,但它不起作用。我将按钮复制到了数据表的外部,一切正常。

I want to update a button in the header facet of a primefaces datatable and it does not work. I copied the button outside the datatable everything works fine.

当数据表的filter事件被触发时,更新应该发生。我显式更新了数据表,外部按钮和内部按钮。

The update should happen when the filter event of the datatable gets fired. I explicitly update the datatable, the outside- and the inside-button.

目的是在未设置过滤器时显示带有图标的按钮,在使用过滤器时显示另一个图标。在此示例中,我简化了用例:当不使用过滤器时,会有一个开锁图标,如果在过滤器中键入内容,则应显示一个闭锁图标。要释放锁,必须单击按钮(我没有实现数据表中过滤器的删除)。

The intention is to display a button with an icon when no filter is set and another icon when a filter is used. In this example I simplyfied the use case: when no filter is used there is a open-lock icon, if I type something in a filter a closed-lock icon should be displayed. To release the lock one has to click the button (I did not implement the deletion of the filter in the datatable).

据我了解,我使用了正确的ID标题内的按钮。所以我不知道为什么这不起作用?

From what I understand I use the correct ID of the button inside the header. So I do not know why this does not work?

我正在使用mojarra 2.2和primefaces 6。

I am using mojarra 2.2 and primefaces 6.

<h:form id="id_form">
    <p:dataTable
        id="id_table"
        value="#{stateController.names}"
        var="currentName">

        <p:ajax
            event="filter"
            listener="#{stateController.markLocked()}"
            update="id_table id_form:id_table:id_button_inside id_form:id_button_outside"/>

        <p:column
            filterBy="#{currentName}"
            filterMatchMode="contains">
            <f:facet name="header">
                <p:commandButton
                    id="id_button_inside"
                    action="#{stateController.markUnlocked()}"
                    icon="#{stateController.locked ? 'ui-icon-locked' : 'ui-icon-unlocked'}" 
                    update="id_form"/>
            </f:facet>
            <h:outputText value="#{currentName}" />
        </p:column>
    </p:dataTable>

    <p:commandButton
        id="id_button_outside"
        action="#{stateController.markUnlocked()}"
        icon="#{stateController.locked ? 'ui-icon-locked' : 'ui-icon-unlocked'}" 
        update="id_form"
        />
</h:form>





@Named(value = "stateController")
@SessionScoped
public class StateController implements Serializable
{
    private boolean locked;
    private List<String> names;

    @PostConstruct
    private void init()
    {
        locked = false;
        names = new ArrayList<>();
        names.add("peter");
    }
    public void markLocked()
    {
        locked = true;
    }
    public void markUnlocked()
    {
        locked = false;
    }
    // getter + setter omitted
}

I还尝试将按钮放在单独的列中。使用此按钮(显示在数据表的每一行中),所有内容也都可以正常运行。

I also tried to put a button in a separate column. With this button (which is displayed in every row of the datatable) everything works fine as well.

推荐答案

有点晚了,

要解决Filou的问题,您需要在dataTable外部定义remoteCommand并使其更新dataTable的标头方面。

To solve Filou's problem, you need to define remoteCommand outside dataTable and make it update dataTable's header facet.

<p:remoteCommand name="rmtCommand" update="id_form:id_table:id_button_inside"/>
<p:dataTable
    id="id_table"
    value="#{stateController.names}"
    var="currentName">

    <p:ajax
        event="filter"
        listener="#{stateController.markLocked()}"
        oncomplete="rmtCommand()"/>

这篇关于在f:facet name =“ header”中更新Primefaces数据表。不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆