0

Given: a primefaces 5.3 application with the following xhtml

    <h:form id="form" enctype="multipart/form-data">
        <p:messages id="serversMessages" showDetail="true" autoUpdate="true" closable="true" />

        <p:selectOneListbox value="#{servers.model.selectedServer}" style="min-width:300px">
            <p:ajax event="change" listener="#{servers.onServerSelected}" update=":form" />
            <f:selectItems value="#{servers.model.servers}" var="srv" itemValue="#{srv.serverInfoId}" itemLabel="#{srv.name}" />
        </p:selectOneListbox>

        <p:column><p:inputText value="#{servers.model.edit.name}" /></p:column>
        <p:commandButton id="newServerBtn" actionListener="#{servers.onNewServerClicked}" value="New" update=":form"></p:commandButton>
        <p:commandButton id="updServerBtn" disabled="#{empty servers.model.selectedServer}" actionListener="#{servers.onSaveClicked}" value="Save" update=":form"></p:commandButton>
        <p:commandButton id="tmpServerBtn" actionListener="#{servers.onTempClicked}" value="Temp2" update=":form"></p:commandButton>

    </h:form>   

When: I click on the updServerBtn (it's enabled when an item in the list has been selected)

Expectation: The backing bean method will be called.

But actually: The backing bean method is NOT called.

Observations:

  1. If I remove the disabled property the backing bean is called.

  2. The tmpServerBtn invokes a backing bean method.

  3. When I click on the updServerBtn, an XHR happens with a 200 response.

Analysis:

It would seem like that Primefaces is deciding that it is not worthwhile to call the backing bean method.

Similar Questions

Before posting my question, I did find this post here:

commandButton/commandLink/ajax action/listener method not invoked or input value not updated

When I remove the disabled attribute of the updServerBtn, the backing bean method does get invoked. This suggests to me that the possible causes of problems in the above post, probably don't apply.

Community
  • 1
  • 1
Hayden Jones
  • 114
  • 4

1 Answers1

-1

I guess your problem is that when you select a server from the selectOneListBox, your button is not updated and thus, disabled attribute is not recalculated.

Try to change the update attribute of <p:ajax> change event. Instead of update :form try to update @form.

malaguna
  • 4,183
  • 1
  • 17
  • 33
  • Nope, button was clickable. A disabled button is unclickable in first place. If you can't be certain or can't test/reproduce the problem on your own, better post a comment. – BalusC Jan 20 '16 at 16:58
  • You are right @BalusC – malaguna Jan 20 '16 at 17:03