File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes a4j:commandButton - Disabling and enabling problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "a4j:commandButton - Disabling and enabling problems" Watch "a4j:commandButton - Disabling and enabling problems" New topic

a4j:commandButton - Disabling and enabling problems

Marty Phee

Joined: Feb 02, 2010
Posts: 2
<a4j:commandButton value="Add New Report Distribution" id="add_report_distribution_button"
<a4j:actionparam name="distReportId" value="#{rptDistCtlr.distReportId}"/>

If I remove the "disabled" property the button behaves as expected and calls rptDisCtlr.createReport... Though if I do use the disabled property as above it just posts the page back and doesn't call my action. The button is disabled/enabled as expected and the rich:panel that it's within gets refreshed (there's a table inside it), but the action isn't called when I click the button to add a new Report.

The html generated is the same.
<input type="button" id="j_id61:add_report_distribution_button" name="j_id61:add_report_distribution_button" onclick="A4J.AJAX.Submit('j_id61',event,{'oncomplete':function(request,event,data){document.getElementById('add_edit_report_dist_panel');},'similarityGroupingId':'j_id61:add_report_distribution_button','parameters':{'distReportId':'1001','j_id61:add_report_distribution_button':'j_id61:add_report_distribution_button'} } );return false;" value="Add New Report Distribution" autocomplete="off" tabindex="0"/>

<input type="button" id="j_id61:add_report_distribution_button" name="j_id61:add_report_distribution_button" onclick="A4J.AJAX.Submit('j_id61',event,{'oncomplete':function(request,event,data){document.getElementById('add_edit_report_dist_panel');},'similarityGroupingId':'j_id61:add_report_distribution_button','parameters':{'distReportId':'1011','j_id61:add_report_distribution_button':'j_id61:add_report_distribution_button'} } );return false;" value="Add New Report Distribution" autocomplete="off"/>

Marty Phee

Joined: Feb 02, 2010
Posts: 2

The value of #{rptDistCtlr.enabledAddButton} was at the request level. So each time the request was made it thought the button was disabled and it never called the action. I made sure to check the state of the button on PostConstruct method and everything works fine now.

I saw another post which mentioned something similar and it made me think about that. I changed the bean scope to session and it worked so I just had to rework it a little to track the state of the button.
I agree. Here's the link:
subject: a4j:commandButton - Disabling and enabling problems
It's not a secret anymore!