Tuesday, 17 November 2015

region refresh after a button is clicked

Lets begin with an use case - I have got reusable taskflow which is drag&dropped on a page as a region. It should be refreshed each time the button is clicked. Easy? Easy!

To explicitly check if task flow is refreshed, I've used System.out stream to log messages. Whole initial implementation (bean, view activity, task flow diagram, bean definitions and the test page itself).






I'd like to have test message logged each time a button is pressed. It can be done with a lot of java code, but I won't write any java code more than test method. I'll print screen actions performed to implement the requirement.





What has happend? Step by step. First of all I need to have something which gives me more or less a random value. A value which will change on each request. Defining java.util.Date as a bean in the request scope in adfc-config.xml file I have got ability to get current date in EL expression. Inspiration can be found on one Duncan Mills post.

My reusable task flow must be extended with additional input parameter. I've named it refreshIndicator and marked it as mandatory. But it can stay optional too.

Changing task flow interface, each page definition must be updated with the new parameter. But do not set it with #{now} expression. I've used pageFlowScope memory to store the "random" value. Request scope is too low - the page or the region can invoke multiple requests during its lifetime. And the requirement was to refresh it only after a button is clicked.

The second change in the page definition file is value of task flow Refresh attribute - IfNeeded means that a task flow must be refreshed if any binding parameter value is changed. In this case if refreshIndicator parameter is changed.

So the last step is to update #{pageFlowScope.param} with #{now} value after a button is clicked. The easiest declarative way is af:setPropertyListener. And that's it. Below is the result:


Tuesday, 6 October 2015

High Available (HA) checklist for ADF applications

Making ADF application HA enabled, there are two groups of actions that should be performed. One is the configuration and the second is the development part of work. Below you'll find my checklist:
  1. in adf-config.xml descriptor put code <adf-scope-ha-support>true</adf-scope-ha-support>
  2. in weblogic.xml descriptor set session persistent store type as REPLICATED_IF_CLUSTERED
  3. each application module must have jbo.dofailover attribute set to true
  4. if you're using POJO DataControls, you need to implement three methods there: createSnapshot(), restoreSnapshot(Serializable handle) and removeSnapshot(Serializable handle); more about that here: Creating and Configuring Bean Data Controls
  5. each bean defined in the memory scope higher than request level must implement java.io.Serializable interface
    • avoid using java transient keyword regarding to the bean attributes
    • each attribute that extends UIComponent aren't serializable! if UI component must be binded with the code, use org.apache.myfaces.trinidad.util.ComponentReference wrapper there
    • make the framework aware of changes that needs to be replicated against the cluster, mark the scope as dirty, ie. using ControllerContext.getInstance().markScopeDirty(AdfFacesContext.getCurrentInstance().getViewScope());
  6. each page flow and session attributes must implement java.io.Serializable interface
 As short as possible. Hope it'll be helpful :)

Thursday, 16 July 2015

what is page definition scope? how many instances of the data controls will be created at runtime?

Asking question about pageFlowScope, sessionScope and others leads to one of the most important (in my opinion) graphs:

source:http://docs.oracle.com/cd/E24382_01/web.1112/e16181/img/lc_scope.png

What is worth to mention, applicationScope lives with an application within the JVM container. If you have clustered environment, you'll have at most one instance per node (lazy init principle).

Nevertheless, what is page definition scope or data control scope? How many instances of data controlls will be created in runtime? Quote from the docs:

"(...) the binding container, the binding objects it contains, and the values the binding objects reference are defined in session scope."

But it doesn't mean that there is equation one session == one binding container (data control instance). Please notice that ADF introduces taskflows and task flow transactions. If your application uses a lot of task flows as regions on one page and some of them are always creating new transactions (on the controller level), per each session you'll have more than one binding frame.

As a summary - from the time point of view, each data control instance (each binding container) will live as long as user session exist. From the instances count point of view, per each session you'll have 0..n instances of the data controls (depends on total number of used task flows on your pages, task flow transaction setting and the page definition contents).