Thursday, March 20, 2014

Shortcut to Call Custom View Row Method from JSF Expression

There is a custom method in Generic View Row Implementation class and you need to invoke it from UI. What would you do? Most likely you would generate Java View Row Implementation class for the specific VO, publish custom method through the interface and later consume it through ADF bindings. This works, but there is a shortcut - especially well working for generic solutions.

Sample application - RowIndexAppADF.zip, implements a table with row status displayed in each row. Once user is changing data, row status is updated - this is the use case, to display row status generically for each row:


We can see from the log - row status is evaluated for each row:


Such check is implemented without a method binding in Page Definition, instead we are accessing current row (available in the table context) and from the row getting row object (the one that represents actual VO row). Next from row object, invoking our custom method, implemented in generic View Row Implementation class - row.row.checkRowStatus:


There is a generic View Row Implementation class, View Object in the sample app extends from this class:


Generic View Row Implementation class contains our custom method, invoked from ADF UI - getCheckRowStatus:


Pay attention, in JSF expression, get part is omitted from the method name: row.row.checkRowStatus.

I believe, this is simple, but very effective technique.

4 comments:

  1. Thanks. Definitely an effective technique..there are case where i used method binding for this type of scenarios.

    ReplyDelete
  2. Hi.
    cool, but mvc pattern is broken

    ReplyDelete
  3. I don't think it is broken, you are still using table binding, defined in Page Def to get a row. From row object we are getting current row instance and calling a method (same as you would call estimatedRowCount, for example). If it would be broken, then with the same success you can say it is broken when getting attribute hint for the label (for example label).

    Regards,
    Andrejus

    ReplyDelete
  4. Do u have example of method which accepts one or two parameters ??

    ReplyDelete