17 Sept 2016

Customizing View Link Where Clause

Master-detail behavior is one of the most common use cases. Whenever we need to implement master-detail relationship between  two view objects we use view links for that. Usually, we do that declaratively with JDeveloper's wizard. The corresponding where clauses will be generated by the framework at runtime. For most cases it's enough, it works fine and we don't need to worry about anything else.

However, sometimes the definition of master-detail relationship is not that trivial.  For example, there is a page containing employee's details and a list of employee's colleagues. Like this:

We're building Employee-Colleagues master-detail relationships with the following view link:

Basically, we are selecting all employees of the same department. But! In this case the colleagues detail list will contain the master employee as well. The employee will be shown twice: on the form and in the colleagues list. We don't want that and we'd like to exclude the employees from their colleagues list.

We are adding one more pair of attributes to the view link definition:

The framework at runtime will generate the following where clause for selecting colleagues:

Obviously, this is not what we actually want. So, we're going to manually specify the where clause to be used for this view link in the property inspector:

And now it will work as it is supposed to, selecting all employees of the my department except myself.

The sample application for this post is available here. It requires JDeveloper

That's it!

No comments:

Post a Comment

Post Comment