Wednesday, May 5, 2010

ADF Declarative Dialog Component

Custom dialog component is one of the components that can be used across the pages declaratively with little code.

This could in following cases

* Displaying custom messages like "Your changes have been saved "(Could also be done using FacesMessage)

* Confirmation dialog where we ask user if he/she want to go ahead or not like "Do you want to save the changes?".

* Custom confirmation dialog like "Would you like to create personal or business address?" with 2 buttons.

This component presently supports upto 5 buttons and can be invoked from JavaScript (declaratively) as well as Java (1 line).

Note: This is a functional pattern and uses the raw javascript for finding the dialog. This might not be forward compatible with all versions of ADF.

You can download the source application with test application here.

Tuesday, April 27, 2010

How to set focus using Javascript and Java

There are scenarios when we want to focus on a particular UI component.
There are many possibilities but here i explain some of the basic cases.

Note: You have to set clientComponent="true" for the component to be focused.
Case 1: Default focus when a page is rendered

For this case we can set the initialFocusId for page document where pt1:it2 is the absolute id.


Case 2: Using JavaScript after Page is rendered (on some action)

function customScript(evt) {
var source = evt.getSource();
var it = source.findComponent("it1");
//var it = AdfPage.PAGE.findComponentByAbsoluteId("pt1:it1");


Case 3: Using java in managed bean

-- Java method goes here

public void TestFocus(ActionEvent actionEvent) {
// Add event code here...

FacesContext context = FacesContext.getCurrentInstance();
String textId = "pt1:it1"; //popup.getClientId(context);
StringBuilder script = new StringBuilder();
script.append("var iptext = AdfPage.PAGE.findComponent('").append(textId).append("'); ").append(" iptext.focus() ");
ExtendedRenderKitService erks =
erks.addScript(context, script.toString());