It is a common use case, when user inserts new row into table and we want to prevent him from inserting one more row, before currently inserted row is not stored into database. Some customers like to have such functionality. You can implement this requirement with ADF pretty easily, just need to specify expression language for RowSelection property. I did a bit more and implemented complete use case, I will describe it today.
Download sample application - DynamicSelection.zip. This sample implements conditional check for Create button - it makes it disabled, when current row is a new row. I'm using ADF table clickToEdit functionality, this allows to improve table data rendering perfomance:
The problem with default implementation - user can select any other record and Create button will become enabled again, even user still didn't saved new record into database:
We want to prevent this and make sure Create button remains always disabled, when there is new (not yet saved) record available. We can achieve this by substituting default RowSelection property value with expression language:
I will change single value to the following expression language statement:
You can see that I'm accessing custom method to get information about current row status (New, Unmodified, etc.) and if current row is not newly inserted row - selection will be enabled, otherwise it is disabled. Its a key thing - it will disable row selection, when there will be new row in the table (before it is saved).
Same custom method is used to disable/enable Create button itself:
Now, when there is new row - Create button remains disabled always and user cant select any other records, because table record selection is conditionally disabled:
When the record is saved - Create button becomes enabled and user can select records again:
Custom method to check if current row is a new row is coming from View Object implementation class: