Sunday 6 January 2013

Perform a Default Button Action for a Page and Particular Region

If you are in any page and think that if you pressed Enter Key then need to perform some actions by default is nothing Default Button Action. In a Web based application default button action is required. If you want to achieve then we need to use the following tags.

Before using the below tags need to consider the below points for giving an Id to the attribute.
  • Identifiers are relative to the component, and must account for Naming Containers.
  • Use a single colon(:) to start the search from the root
  • Use a multiple colons to move up through the Naming Containers( :: for One Level Up, ::: for two Level Up and etc.,)

<af:form>
The UnifiedForm component creates an HTML <form> element and can able to use only one af:form component per page. There is property called 'defaultCommand', is going to use for set the default action of the form/page.

The property of 'defaultCommand' value is an id attribute of the command button inside the form whose action should be invoked by default when the enter key is pressed with focus inside the form. If defaultCommand is not specified, no action is invoked when the enter key is pressed with focus inside the form.


<af:subform>
The Subform represents an independently submittable region of a page. The contents of a subform will only be validated (or otherwise processed) if a component inside of it for submitting the page or if the default attribute is set to true while no other subform is responsible for submitting the page.
  • This allows for comparatively fine-grained control of which components will be validated and pushed into the model without the compromises of using entirely separate form elements.
  • Should not have a component with immediate set to true in a subform. A Component with immediate set to true will still be validated even though the containing subform is not responsible for submitting the page.

The property of 'default', whether the subform should assume it has been submitted. When set to "true", "submitted" will be considered true if no other subform has been submitted.

The property of 'defaultCommand' value is a client id of the command component inside the subform whose action should be invoked by default, when the enter key is pressed with focus inside the subform. This attribute overrides the defaultCommand set on form.


ADF strongly recommend the use of a single <af:form> per page, and using <af:subform> where you might otherwise be tempted to use multiple forms. Multiple forms require multiple copies of page state, and user edits in forms that aren't submitted are always lost. When a page using subforms is submitted, page state is only written once, and all user edits are preserved.

For more details check with sample.

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R2 Update3]

How to run this sample?
Run using the PageDefaultButtonAction.jspx and check the behaviors <af:form> with Default Command Actions by pressing Enter Key & RegionDefaultButtonAction.jspx and check the behaviors <af:subform> with Default Command Actions by pressing Enter Key.


Triggering an UnCommitted/Not Saved Data Warning While closing and Navigating a Page

In general, if you are modifying some data on the page then you worked other activities then you are trying to close, if it is closed without showing any warning then we need to lose all our data. Here we are stopping if it contains any uncommitted data.

The property of 'uncommittedDataWarning' under the <af:document> is going to be used for showing the UnCommitted Data Warning While closing and Navigating a Page.

<af:document>
The document component creates each of the standard root elements of an HTML page: <html>, <body>, and <head>, but by abstracting away from those components, can be used in non-HTML pages as well.

The below points need to be consider while using,

  • Only one document component per page is allowed.
  • Documents must not be placed inside of page templates.

The property of 'uncommittedDataWarning', specifies whether users should be warned about uncommitted data when navigating off the page or region. Setting this property to 'on' will enable the warnings. It is not supported on the 'org.apache.myfaces.trinidad.core' renderkits.



For more details check with sample.

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R2 Update3]

How to run this sample?
Run using the UnCommittedDataWarning.jspx and check the behaviors by typing some values in the Name field and press the F5, it will show the uncommitted data warning message.

Saturday 5 January 2013

Making a MDI Application by using the MultiTaskFlow

Multiple Document Interface (MDI) is an application style you can use to open multiple windows (called sheets/tabs) in a single window and move among the sheets. It is a most common thing and used desktop applications. Now we can achieve same by using multi task-flow concept of ADF and customize as per our business requirement.

In ADF Application, we can achieve by using multi task-flow concept and making the Java class with Collections to handle the multiple sheet adding, removing, selection and closing. Please follow the below steps,

  • Create a Java Class of MDI.java & Sheet.java and use the property by using the Collection with wrapper of TaskFlowBindingAttributes and Sheet classes.


  • Create a Page by using the ADF Page Template and include a af:panelTabbed with af:showDetailItem dynamically by using the af:forEach looping.


  • Create a PageDef for Template and include a ‘multiTaskFlow’ tag under the <executables>



  • Include a <definitionFactories> for TaskFlowBindingDefFactoryImpl under the DataBindings.cpx file.



For more details check with sample.

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R2 Update 3 + HR Schema]


How to run this sample?
  1. Create Data Source of ‘HrDS’ under Weblogic Server.
  2. Open an Application and deploy jar for MDIApplication & HrModel projects.
  3. Expand a HrUI and run using the Run.jspx.

Friday 4 January 2013

Generic way of Data Passing between UI Layer and Model Layer


Requirement is used to access the User Login HTTP Session Data from UI Layer to Model Layer for doing some Business Validation like checking the user is Already logged in or not, Passing the Login Date as default for all ViewObjects and etc.,.

In general, if want to pass the data from UI Layer to Model Layer then need to use the 'Action' bindings. From 'Action' bindings we need to pass the data and store it in AM, from that can access across the View Objects for the business requirements. If we are doing in this way then need to add the action bindings entry in each pageDef files. In case it is Task-flow with Begin New transactions then each task-flow will has its own transaction and it has many pageDef then need to take care all places.

For avoiding all, If we are using the DataControlFactoryImpl then no need of any pageDef entry. Only one included entry on the BC4JDataControl tag of DataBindings.cpx itself enough.

Need to follow the below steps for achieve the Generic way of Data Passing,

  • Need to create custom class by extends DataControlFactoryImpl and override the method of getDataControlClassName() and need to return the class name of custom class by extends JUApplication.


  • Need to create custom class by extends JUApplication and override the method of beginRequest() and write a logic of passes all the session scoped attributes to the underlying Application Module.


  • Open the DataBindings.cpx file and added the entry against the property of ‘FactoryClass’ underlying the tag BC4JDataControl


For more details check with sample.

[Runs with Oracle JDeveloper 11g R2 Update 3 + HR Schema]

How to run this sample?
Run using the Run.jsf and check the Generic Data Passing by followed a below steps,
  1. In Main Page click the Store on session button and see the console (it shows the actual value stored in the session with Key/Value pair).
  2. Press the ‘Employee’ Button then it will load an Employee Page. At the time of loading it will pass the UI Layer data into Model Layer via CustomDataControlFactoryImpl
  3. Now click the ‘Print UI Session Data’ Button and see the console, it will print the actual UI Layer Data into Model Layer