JSF ajax命令按钮不更新primefaces选项列表

时间:2022-04-16 20:01:45

This is the code:

这是代码:

<h:form id="articleForm" >
    <p:commandButton value="Select tags" ajax="true" >
        <f:ajax execute="@form" render="@form :articleForm:tags" />
    </p:commandButton>

    <p:pickList id="tags" value="#{articleController.dualListModelForTags}" var="tag" itemLabel="#{tag.tag}" itemValue="#{tag}" converter="distinctTagConverter">
        <f:facet name="sourceCaption">Distinct tags</f:facet>  
        <f:facet name="targetCaption">Connected tags</f:facet>
    </p:pickList>
</h:form>

When the commandbutton is clicked, the getDualListModelForTags() in the backing bean is called and executed. In getDualListModelForTags() I make some modifications so I want the picklist to be updated. But the picklist(id=tags) is not rendered again. Only when I refresh the page, are the modifications made to the picklist.

单击命令按钮时,将调用并执行辅助bean中的getDualListModelForTags()。在getDualListModelForTags()中我做了一些修改,所以我想要更新选项列表。但是不会再次呈现选项列表(id = tags)。只有当我刷新页面时,才会对选项列表进行修改。

1 个解决方案

#1


12  

The PrimeFaces <p:commandButton> component doesn't work together with <f:ajax>. You need to use the button's own ajax-targeted attributes instead. Instead of the <f:ajax execute> you should use <p:commandButton process>. But this already defaults to @form, so you can omit it. Instead of the <f:ajax render> you should use <p:commandButton update>. Specifying client IDs which are already covered by @form is unnecessary, so just @form is sufficient. Also the ajax="true" attribute is unnecessary as that's the default already.

PrimeFaces 组件不能与 一起使用。您需要使用按钮自己的ajax目标属性。而不是 ,你应该使用 。但是这已经默认为@form,所以你可以省略它。而不是 ,你应该使用 。指定@form已经涵盖的客户端ID是不必要的,所以只需@form就足够了。此外,ajax =“true”属性是不必要的,因为它已经是默认属性。

So just this should do:

所以这应该做:

<p:commandButton value="Select tags" update="@form" />

Unrelated to the concrete problem, you're doing the business job inside a getter method. This is a bad idea. Do it in the button's action method instead. You also seem to be using a session scoped bean for view scoped data. This is a bad idea. Put the bean in the view scope instead.

与具体问题无关,您在getter方法中执行业务工作。这是一个坏主意。而是在按钮的操作方法中执行此操作。您似乎也在使用会话范围的bean来查看作用域数据。这是一个坏主意。将bean放在视图范围中。

#1


12  

The PrimeFaces <p:commandButton> component doesn't work together with <f:ajax>. You need to use the button's own ajax-targeted attributes instead. Instead of the <f:ajax execute> you should use <p:commandButton process>. But this already defaults to @form, so you can omit it. Instead of the <f:ajax render> you should use <p:commandButton update>. Specifying client IDs which are already covered by @form is unnecessary, so just @form is sufficient. Also the ajax="true" attribute is unnecessary as that's the default already.

PrimeFaces 组件不能与 一起使用。您需要使用按钮自己的ajax目标属性。而不是 ,你应该使用 。但是这已经默认为@form,所以你可以省略它。而不是 ,你应该使用 。指定@form已经涵盖的客户端ID是不必要的,所以只需@form就足够了。此外,ajax =“true”属性是不必要的,因为它已经是默认属性。

So just this should do:

所以这应该做:

<p:commandButton value="Select tags" update="@form" />

Unrelated to the concrete problem, you're doing the business job inside a getter method. This is a bad idea. Do it in the button's action method instead. You also seem to be using a session scoped bean for view scoped data. This is a bad idea. Put the bean in the view scope instead.

与具体问题无关,您在getter方法中执行业务工作。这是一个坏主意。而是在按钮的操作方法中执行此操作。您似乎也在使用会话范围的bean来查看作用域数据。这是一个坏主意。将bean放在视图范围中。