Disable button based on selectedIds

Hi All,
I’ve an Async table control with select row checkbox in one of the columns. and a button which needs to be enabled only if the user selects any of the checkboxes in the table.
I bound my async table to a ISelectableTableContentProvider and set the disabled property of the button to #{empty ..rowSelectedIds}
When the initial page loads, the button is disabled which is correct but after i select the checkbox in the table the button doesnt get enabled.
when i print the rowSelectedIds then i see the values selected.

Is this implementation correct, As i was expecting the button to be enabled once the user selects any of the checkboxes.
I’ve seen this implementation when customizing the temporary attachments provider on the remove button.
Is there something different in the implementation of attachments provider.

Thanks,
Sravan

You will need a Script Block control in your CAF view that listens for the row selection events and updates the disabled state of your button.

See: http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuites/wmsuite8-2_sp2/My_webMethods/8-2-SP1_CAF_JavaScript_Reference/CAF.Table.Model.html#addRowChangeListener

For example, add a Script Block control and set the value property to something like this:


CAF.model('#{caf:cid("yourTableIdHere")}').addRowChangeListener(
  function(id, rowId, type) {
    if (type != 'select') {
        return;
    }
    var disabled = true;
    if (  CAF.model ( id ).getRowSelectedCount () > 0 ) 
    {
      disabled = false;
    }
    CAF.model('#{caf:cid("yourButtonIdHere")}').setDisabled(disabled);
  }
);

Thanks Eric for the code snippet.
I understand that it works with the below script, what i do not understand how does it work in Attachments Provider without a similar script.

How we can set buttonID dynamically.I think we need to set buttonID same as rowID.
I have tried to set it with rowID but getting error as “[POP.001.0002] A “javax.portlet.PortletException””

You want the button in the row that was just selected?

If, so the something like this should work inside the rowChangeListener fuction.

//get model for the row
var rowModel =CAF.model(rowId);
// Calculates the global id for the control in this row with the specified local id
var buttonId = rowModel.getControlId("localButtonIdHere")
//get the button model
var buttonModel = CAF.model(buttonId);
//disable it.
buttonModel.setDisabled(disabled); 

Thanks Eric.
Using this Script I am able to retrieve individual Button-ID. However button is not getting disabled.


//buttonModel is returning as function event
var buttonModel = CAF.model(buttonId); 
//output of buttonModel
function onclick(event){
;CAF.model(this).go();
}
//Button disabled is not working
buttonModel.setDisabled(disabled); 

Thanks

Thanks Eric.
Its working now.There was some mistake in script.So control was not getting to next step.

Thanks
Baharul