Dive into Oracle ADF

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 8:12:23 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Search blog with Google:
 

Search BC4J JavaDoc:
 

May 2003
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Apr   Jun

Get Firefox!

Tuesday, May 13, 2003

"How can I write validation that is conditional based on some external criteria?"

In trying to solve this problem, some developers think to write validation logic in their ViewRowImpl class, because it seems like the entity object is not the right place to do it. However, the validate() method on the ViewRow is never explicitly called as part of the framework's validation cycle, so it's not the right place to accomplish the job. The validate() method on ViewRow exists so that the client can force validation to happen explicitly on that row. Only the entity object is a failsafe place to put validation logic, and this is very much by design.

If you need to write business rules that behave differently based on some external factor -- an example that came up today was a question about how validation rules could behave differently if a user was known to be a manager -- then you should take advantage of BC4J's user-data feature on the session object. To get hold of the user data Hashtable, you can call getSession().getUserData() from inside your application module implementation class (perhaps in a custom method that you write there), or in an overridden prepareSession(Session) method after calling the superclass' implementation. You can put values into this hashtable that will remain for the duration of the current user's session with the application module.

Then, within your entity object validation method, you can write code like getDBTransaction().getSession().getUserData() to get access to the current user's session user data, and check the values of entries there to make your validation conditional based on them.


11:53:30 AM    



© Copyright 2008 Steve Muench.