3

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.

BigJ
  • 1,990
  • 2
  • 29
  • 47

1 Answers1

13

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.

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Excellent answer. I guess you know i'm using session scoped beans because the bean vars remain during a page refresh. But why would a view scope be better? – BigJ Jan 18 '12 at 13:28
  • 1
    Because you're dealing with view scoped data, not with session scoped data. If you treat view scoped data as session scoped data, then the endser may see inconsitenties whenever the enduser has the same page (view) open in multiple windows/tabs in the same browser session and switches between it after every interaction. – BalusC Jan 18 '12 at 13:32