Wednesday, 16 November 2016

parameterized bind iterator name as a mean to achieve reusable UI part in ADF12c

    This is a real-life use case that I'm usually hitting at the customers. There is a table which appears in the data model more than once. The business rules are the same, reusable, because they're implemented on the entity level. But to make it much more reusable, I want also to have the same front-end for them. In other words, I don't want to drag and drop each iterator from the data control and adjust the same visual rules to them each time (and change them in several places). Is there a way to do it just once per project? Well, there is.

    Lets start with preparation of the environment. I will base on REGIONS and COUNTRIES tables from HR scheme. My reusable part of the UI will be a region. There will be just one input parameter - iterator name. In the taskflow, I don't need nothing more than the view page. Just to create all needed files, structures and bindings, I'm drag and dropping one of the CountriesView iterator on it.

    And now the most important step of all. The taskflow parameter must be set in the page definition. When you select iterator binding, in the Property Inspector you get Binds attribute. It can accept EL expressions, but as I can see, in 12c you must type it manually. Another important note here, it must be evaluated with $ sign instead of #. Put ${pageFlowScope.iterName} there.

    To finish this proof of concept, create a test page, drag Regions iterator as a table. Drag and drop countriesBTF as a region and put CountriesView iterator names for both of them. After that you can run the test.

    One of the region is filtered with the view link, second is not filtered by default. First is refreshed after you'll change the current row of the Regions (master) iterator. Such behavior is an implication of shared data control scope.

    Hope you'll find it useful :)

Monday, 17 October 2016

af:form default command use-case

   Recently I've done some simple application. As usually, there was a logging page, which I have developed following rules from the documentation. The mechanisms were working fine, but there was one user who has pointed a change request - he wanted to facilitate the logging in process. Now he need to use a mouse to click the button, instead he wants the form to be submitted with Enter key. Useful change, to improve user experience with the app I should start with the login page. 

   I've been checking for <af:commandButton> properties in order to find an attribute that would solve it. Unfortunately there was nothing suitable, and, it is not a place for specifying default action. In many cases developers may set such property to more than one components. During short and temporary insanity I've thought about JavaScript function to do the work :)

   Fortunately there is a solution. Simple and quick. Similar to rendered attribute, it is not the component that should be triggered in order to present (or hide) itself. It is the container. There is an attribute, defaultCommand, which must be set in <af:form> tag. And that's it :)

   And short quick note at the end - it supports EL expressions, so the action may be parameterized.

Tuesday, 2 August 2016

how to implement tokenized messages in ADF-Faces

    Some time ago I've posted an article about customizing error messages in BC4J. Now's the time to think more about the UI. From time to time there is a requirement to write a sentence or a string concatenation on the screen which won't be static. As an example: There are XYZ rows from which ABC are shown on the screen. Of course my application must be internationalized, I'm using the bundle file. I can split my sentence into three different entries in the bundle file but I must be sure that the syntax in each language is the same. And it mustn't be like this.

    The solution is simple and, as usually, no extra Java code. ADF-Faces allows to tokenize text message. My simple use case is to display two fields and write "a+b is aANDbSUM" at the bottom of the page. For that purpose I'll use af:format3 function. It is a part of EL expression and it can be mixed with other valid EL invocations inside.

    The code snippet (it is using static text and viewScope implicit variables just to simplify the example):
<af:outputText value="#{af:format3('the sum of {0} and {1} is {2}.', viewScope.v1, viewScope.v2, viewScope.v1+viewScope.v2)}" id="ot1" partialTriggers="it2 it1"/>

    And the screenshots of the code and of the running page: