Custom Java Bind Variable in a Where Clause of an ADF View Object

Posted on Updated on

You can make a JDeveloper model View Object (VO) use a data query that has a custom variable accessor in Java.  This is useful for cases where you want your where clause to select based on the current user name from the ADF Security context.

Go to the “Query” tab of your view object:


Add a new Bind Variable and make sure to specify “Expression” and give the value the Groovy expression “adf.object.viewObject.yourPropertyName”.  The “adf.object.viewObject” portion is essentially like saying “this object” and then it will call getYourPropertyName() to fetch the value:


Back in your query expression, refer to this new bind variable by its name but prepend “:” to indicate that it is a bind variable as shown above.

Select the “Java” tab of your view object and then click the pencil icon to edit the settings:


Select the “Generate View Object Class” and “Include bind variable accessors” options:


This will generate a new “.java” entry under your view object in the JDeveloper application navigator:


Finally, open that Java file and change the implementation of your get accessor as you wish.  In my case, I am simply returning the user name property from the ADF security context.  I also changed my set accessor to do nothing:

Advertisements

2 thoughts on “Custom Java Bind Variable in a Where Clause of an ADF View Object

    […] Creating an LOV from a concatenated field in Oracle JDeveloper Posted 9 April 2010 Filed under: Uncategorized | Recently I had the need to show a List of Values drop down with a value generated from two database fields.  Not surprisingly these fields were first_name and last_name.  Creating the query was fairly simple and used some ideas gleaned from this post. […]

    Matt Cooper responded:
    April 16, 2010 at 5:18 pm

    Potential simplification depending on your needs:

    It turns out that there is a Groovy variable for the specific example shown above. Rather than using the “adf.object.viewObject.myEmailAddressBindVariable” Groovy expression and a Java implementation of the view object, you can simply use an expression of “adf.context.securityContext.userName”.

    Of course if you needed to do anything more custom than simply using the user name, you will still need to create the Java implementation and use the viewObject expression syntax.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s