Tuesday, June 10, 2008

Entities revisited


Hey folks,


I had an interesting problem which you might be interested in knowing about.


The application I am building currently has a page where you open a dialog and can edit a particular child record. This update screen allows the user to change (among other things) the FK to the parent view object which is on the page the dialog returns to.

There is a little pencil icon. This opens the dialog. Save in the dialog window closes the window and saves the changes.

One of the change they can make as I indicated is to the parent data, which is the designation which parent the child record has.

The interesting thing here is that because I am using drop-down lists, I do not have direct access to the FK value when I need it. Specifically if they change the FK value I do not have the new value. If I use value change listener the new value there just shows the integer index into an array. The way to get at the value is to let a cycle go by and catch it once it has been set with a binding for the iterator. But I don't want to (or can't) wait that long. I need that new value now!

When I change the FK value, because of the way ADF automates coordination between parent/child VO instances, the new record is quickly lost! If I look at the current record in that VO instance fairly quickly after the change has been made, this binding layer says my child/FK record no longer exists under that parent/PK. But I really need that new value.

So where is it? Where can I go look? I know it is not totally lost because the child ends up in another parent; but right when I need it I can not find it.

So where to look: in the entity cache. How do we do that?

In the VO Impl code for the child I have code that does the following:

the first line gets the entity definition for the view object. I get the definition for the first entity associated with the VO because I know the VO only has one entity associated with it. Next I get the app module (again in my app there is only one), and use that to get the particular entity I am looking for. So I use findByPrimaryKey where I plug in the EntityDef and the Key for the particular VO row I am looking for. Once I have found it I get the attribute I am interested in. ParentFKId, in this case, is the FK which points back to the master record. So now I have my new value!

Yee haw!!

No comments: