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:
Hi andrejus,
ReplyDeleteI have a simple af:table displaying results.
it's rowSelection="single" and editingMode="clickToEdit"
The normal behavior is that the user double clicks the row to edit the selected row entry.Works fine.
If I have a edit button to specifically do the same action(user selects a row,but now clicks on an edit button,without double clicking the row) , can i achieve it through bindings (as there is no edit operation in the data control operations) OR do I have to write a backing bean to make the row editable on click of the EDIT button?
Hi,
ReplyDeleteThe
rowSelection="#{backingBeanScope.mainBean.createEnabled == 'New' ? 'none' : 'single'}"
causes all the rows to be disabled.
Am i doing something wrong ?
Cheers
Hi,
ReplyDeleteIt seems you misunderstood. Its how it should be.
Regards,
Andrejus
Hi,
ReplyDeleteI am trying to generate View Object Interface in my appplication and i am ubable to do so.
Can you let me know how to generate View Object Interface.
Thanks
Ajay
What you mean by "View Object Interface" ? There is not such term. May be you want to expose custom View Object Implementation method through Data Control?
ReplyDeleteAndrejus
Yes, That's what i meant.
ReplyDeleteI am using your Dynamic Selection project and there i see that com.redsamurai.model.views.common.JobsView.java shows as "View Object Interface" in the JobsView(View Object).
So i wanted to generate the same in my application.
Thanks
Ajay
This class will be auto generated, you only need to declare your custom method to be exposed to Data Control. Look into View Object Java section, there is option to expose your custom method.
ReplyDeleteAndrejus
Somehow its not autogenerated in 11.1.1.4 Jdeveloper. Which version of Jdev are you using.
ReplyDeleteDoes this get autogenerated while creating New VO ??
I'm using all versions of JDev ;) And this feature is working very stable. VO interface is never created when you create VO. You must do these steps:
ReplyDelete1. Go to Java section inside VO wizard
2. Create VO Java Implementation class, by editing Java options and clicking check box
3. Open generated Java implementation class, type your custom method
4. Back to Java section inside VO wizard, click option to expose your custom method
5. Select custom method and click OK
6. VO service interface will be generated now :)
Regards,
Andrejus
After Step 2, selected all the checkbox but, a class like JobsView.java was not generated.
ReplyDeleteAnd the custom methods were not visible
Okej, you are not following my steps :) I was saying after step 2 it will be created only VO Implementation class (Impl). You need to implement custom method by yourself. Please refer to ADF developer guide, View Objects section. I see you are missing background info, highly recommend to go through ADF developer guide, this will help to understand much faster.
ReplyDeleteAndrejus
Hi Andrejus,
ReplyDeleteI did exactly the way mentioned.
But whenever i am clicking on Create New, all my rows get enabled not the newly created blank row ?
Any pointers .
Thanks
Sumit
Hi Andrejus,
ReplyDeleteFirst of all, I would like express my thanks for all wonderful blogs you have written and going to write.
You are my favourate.
Coming to the problem I faced,One of colleague helped me in that issue, just wanted to share it .
We can create a transient attribute, the attribute value is derived from an Expression, the expression is this.object.getEntity(0).getEntityState(), which holds the state of the current row in the adf table.
And in the ready only property of that column I am checking the state and making it ediable accordingly .
Thanks
Sumit Yadav
Yes, thats another possible way.
ReplyDeleteAndrejus
Hi Andrejus,
ReplyDeleteI have editing mode as "clickToEdit" for my grid. There are mulitple editable columns in my grid with first column as select check box. As editing mode is "clickToEdit", I have to click thrice to select a row by checking check box. Is there any way i can override "clickToEdit" mode for a particular column?
Thanks,
Arpit
Hi,
ReplyDeleteI believe in 11g R2, it should be possible.
Andrejus
Hi Andrejus,
ReplyDeleteCan I please know how to get the current row from a tree table in the VO Implementation class.
You can try just to get current row of VO. It doesnt return correct result?
ReplyDeleteAndrejus
Hi Andrejus,
ReplyDeleteI am trying to create a clickToEdit table that works like in an auto-update mode i.e. it doesn't require the user to press any button to update the changed record?
To achieve so, is there any inbuilt feature of ADF, a property, that when set triggers the DB Update command and the Table component is refreshed, is applicable?
Many Thanks,
Sam
Hi,
ReplyDeleteI am adding a new row to the table at the end and I need to select that row.How do i do that?
Hi Andrejus,
ReplyDeleteI am having an ADF Table which has about 100 rows per page. So the page has a scroll bar. When i click on like 80th row, the row gets selected (rowSelection is single), but the page jumps to the top of the page.
Any suggestions where am i doing wrong
Thanks
Arun
Hi, great info!!!
ReplyDeleteUnfortunately, it doesn't work in 12.1.3. When you create new row and then select another row, row status change and edit another row go on.
Any suggestion?
Thanks
DEMR
I will need to test it with 12c.
ReplyDeleteAndrejus
Hi Andrej
ReplyDeleteI am new to ADF and this article seems good. I am working on a business request where based on a Status Attribute, if it is Yes, user should not be able to mark the checkbox checked. if N or other statuses user can. Status is visible on the adf table.
I am using ADF 12.1.1.
My approach was to add a changevaluelistener method to handle this but not getting a right way. Request you inputs to handle this.
Hi DJ,
ReplyDeleteI have the same requirement.
Can you please share the solution if you have solved it.