Thursday, October 23, 2014

ADF Train Template

The ADF Train Model is helpful in creating wizard like model where the user can traverse through a series of steps in creating a new entity. For example, in the case of adding a new employee to the Payroll or HR system, there can a wizard kind of model with multiple pages which gets information related to the employee like, Basic Information, Educational Information, Work experience information and so on and so forth. 

Think of a scenario where this wizard model should be consistent across multiple entity creation scenario, like if the user wants to add the employee into a particular project, or a relocation has to be made, everywhere we need this wizard model and the page looks similar everywhere, just that the number of steps and the fields inside the pages gets changing. For achieving this we can create a Train/Wizard template. Wizard is a term used in a desktop application, like in JDeveloper for creating a new Application we traverse through multiple steps like, Application Name, Project 1 Name, Project 1 Java settings etc...

The main things we need to take care of is 
1. Page Template
2. Train TaskFlow
3. Fields


1. Page Template

The page template for the wizard which we create will be a .jspx page.

We can create the page template by Right-clicking on the project and creating an ADF Page template and create a page template.
  • In Document type radio button we should select JSP XML
  • Template Content can be a Blank Template
  • Facet Definition and attribute is where we define our dynamic part and the attributes which we use to control the behaviour of the contents placed in our template. Facet is a portion inside our template where we add the fields which we need respective to each and every individual page of our train. Attributes are like variables we define in our page template so by setting these attributes in the page we can change the behaviour of the Non-editable part of our page.
  • Create page definition is necessary if you are passing any parameters from your Datamodel to the page. Its optional.

After creating the page template we need to add two namespaces for adding the facets and attributes tags in our page template


xmlns:f="http://java.sun.com/jsf/core" 
xmlns:afc="http://xmlns.oracle.com/adf/faces/rich/component"

The train template will contain some basic components like Train (obviously), Back and Next buttons. There will be facet called "fields" (as per this example) which will be where you will put your faces components needed for each page/fragment.







2. Train Taskflow

The train task flow can be created like any other bounded task flow

While creating the views inside the train task flow, you will see that there is train-stop for each and every view.As shown below

  For this train stop we can define the display Name such that it appears on the train component 



This display Name can be set as shown below


This display Name will be picked up by the af:commandNavigationItem inside the template whose text value is set as

text="#{controllerContext.currentViewPort.taskFlowContext.taskFlowTrainModel.currentStop.localActivityId}"
The back and Next buttons are also set with action which will be based on the the train task flow. For Back button the action will be
action="#{controllerContext.currentViewPort.taskFlowContext.trainModel.getPrevious}"
For Next button the action will be
action="#{controllerContext.currentViewPort.taskFlowContext.trainModel.getNext}"

3. Fields

The fields which are specific to the particular page will be added inside the fields facet

We create page fragments view1.jsff and view2.jsff based on the Reference ADF Page Template "Train Template"

After creating the page fragments you drag and drop the fields which you want to show on the page inside the "fields" facet.




For the view1 you need to set the title on the page and disable the back button and enable next button while rendering both the buttons

This is done adding the below xml in your fragment
        
        
        
        
        




The attributes backRendered, backDisabled, backDisabled, nextDisabled and title are defined in the page template.

These attributes are used for setting different properties of different components on the page template.

the Rendered property of Back button is set like:
rendered="#{attrs.backRendered}"

The title of the panel Header is set like:
text="#{attrs.title}"

So attributes help is setting the properties of different components in the Page template and the attributes will also be declared inside the Page template as :

                <afc:attribute>
                    <afc:attribute-name>title</afc:attribute-name>
                    <afc:attribute-class>java.lang.String</afc:attribute-class>
                </afc:attribute>

                <afc:attribute>
                    <afc:attribute-name>backRendered</afc:attribute-name>
                    <afc:attribute-class>java.lang.Boolean</afc:attribute-class>
                </afc:attribute>


2 comments:

  1. is it possible to have a threshhold on the display label of each tarinstop?

    ReplyDelete
    Replies
    1. what do you mean by threshold on the label of train stop ?

      Delete