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:

No comments:

Post a Comment