0

My p:commandButton stops sending actionListeners once I add disabled option. Why is this happening?

I have a p:selectOneListbox which needs to have something selected before OK button is enabled:

<p:selectOneListbox value="#{FileSelectBean.fileNameSelected}">  
  <f:selectItems value="#{FileSelectBean.fileNames}" />
  <p:ajax update=":formFileSelect:okId" />
</p:selectOneListbox>  

And I have an OK button:

<p:commandButton id="okId" value="OK" 
    type="submit" update=":formEncryptionDialog" 
    actionListener="#{FileSelectBean.actionOk}" 
    oncomplete="dlgFileSelect.hide();"
    disabled="#{FileSelectBean.fileNameSelected.isEmpty()}">
</p:commandButton>

Backing bean:

private String fileNameSelected = "";

All works ok without disabled="#{FileSelectBean.fileNameSelected.isEmpty()}". Once I add this, OK button is enabled/disabled properly, but stops calling FileSelectBean.actionOk after button is clicked.

What went wrong?

Edit: I have removed <p:ajax update=":formFileSelect:okId" /> and I refresh a button in some other way, but it did not help. So it seams not related to ajax in selectOneListbox.

Danijel
  • 8,198
  • 18
  • 69
  • 133
  • Just a quick check- is it inside a form? Do you have nested forms? Did you try to set ajax="true" and ajax="false" and see if it changes anything? How do you update the button itself? – bjedrzejewski Mar 19 '13 at 12:46
  • Try adding `process="@this :formFileSelect:okId" to the `p:ajax` tag. – maple_shaft Mar 19 '13 at 12:50
  • It might have something to do with the timing of the update and the scope of your bean. ActionListeners fire before model updates so, depending on the scope of your bean, `#{FileSelectBean.fileNameSelected.isEmpty()}` might not have been updated in time to make a difference. Try changing the `actionListener` to `action` – kolossus Mar 19 '13 at 12:51
  • Thanks but `action` did not help. – Danijel Mar 19 '13 at 13:01
  • @jedrus07 Could you be more specific? – Danijel Mar 19 '13 at 13:02
  • @Danijel I was wondering if you do not have nested forms anywhere, as this is common mistake. You have: disabled="#{FileSelectBean.fileNameSelected.isEmpty()}"> that works apparently. I wonder how are you updating the button itself to make it work? Also- FileSelectBean- what is the scope? Did you also tried to change the listener to: actionListener="#{FileSelectBean.actionOk()}" Code of the listener could be helpful as well. – bjedrzejewski Mar 19 '13 at 13:06
  • OK. No nested forms. I refresh the whole form to update the button after I removed the `ajax` line above. Bean is Request scoped unfortunatelly. – Danijel Mar 19 '13 at 13:18
  • Listener code is not important since the call to `actionOk` is never done. – Danijel Mar 19 '13 at 13:18
  • I had similar problem, once where the problem was the listener code- something not right with signature of the method. Also if you have inheritance it can be tricky. Can you just add the signature of the method to the question? – bjedrzejewski Mar 19 '13 at 13:23
  • You mean this: `public void actionOk(){...}`? – Danijel Mar 19 '13 at 14:10
  • The `#{FileSelectBean}` is in the view scope, right? See also point 5 of http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 – BalusC Mar 19 '13 at 15:31
  • No, it's Request scoped. Just tried View scoped and it didn't work. – Danijel Mar 19 '13 at 15:49
  • Is the commandButton in the :formEncryptionDialog? And to debug add one h:outputText with an id and keep it's value as #{FileSelectBean.fileNameSelected.isEmpty()}. Put outputText id in selectOneMenu's update and checkout the output. – Jitesh Mar 22 '13 at 16:49

1 Answers1

0

Try this:

<p:selectOneListbox id="primeOneListBox" value="#{FileSelectBean.fileNameSelected}">` 
     <f:selectItems value="#{FileSelectBean.fileNames}" />
     <p:ajax event="change" update=":formFileSelect:okId" process=":formFileSelect:primeOneListBox" />
</p:selectOneListbox>

And check if fileNameSelected setter method is called after selection