2

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.

  4. The bean does not work properly when it is View or Request scoped but does work at the Session scoped level.

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
  • I submitted this question last week and it was marked as a duplicate of the existing question, however I feel that is not the case. – Hayden Jones Jan 25 '16 at 17:57
  • 1
    Do you have correct import for `@ViewScoped`? – Geinmachi Jan 25 '16 at 18:45
  • Current the application uses the Scoped annotations in the javax.faces.bean package. – Hayden Jones Jan 25 '16 at 20:53
  • 1
    And your managed bean is `@ManagedBean`? – Geinmachi Jan 25 '16 at 21:02
  • Did you search on actions not being called in combination with the disabled attribute? Several topics to on SO – Kukeltje Jan 26 '16 at 08:29
  • 1
    So your view scoped managed bean is reconstructed on every request (just put debug breakpoint in postconstruct to verify), and it's basically behaving like a request scoped one? That's a different problem: you're actually not using a view scoped bean as answered in that dupe. – BalusC Jan 26 '16 at 08:48
  • @BalusC I think you are correct, that this was probably point #5 on the referenced question. I probably made some kind of error when I said that I tried ViewScoped. – Hayden Jones Jan 27 '16 at 15:36

1 Answers1

-1

I did the following to get things to work:

  1. I made the managed bean ViewScoped

  2. I made the disabled property of the save button a simple boolean field. (Rather than an expression to be resolved by JSF or the backing bean, I don't know if that mattes)

Hayden Jones
  • 114
  • 4
  • what is a simple boolean field? Seems like you 'fixed' something without actually knowing what you do/did. In that case, this Q and A is totally useless to others (at least the A is). You problem is like @BalusC stated in the last comment above. – Kukeltje Jan 26 '16 at 16:52