Tuesday, September 28, 2010

How to reference the value in a ADF Table column declaratively and in Java

I am correcting myself. I think I could not find a way to reference the value in a ADF table column using EL outside the table component.

As we all know, the value in the column of ADF table is referenced by using EL "#{row.AttributeName}", while "row" is defined in the ADF table component attribute - "Var" by default. If there is a scenario that you have to reference the value outside of the table: for example, you have a button outside of the table and will be dynamically disabled if a value in the table is null and enabled if a value is not null. The question is, how you gonna reference the column value out of the table.

Using the IteratorBinding EL is not accessible, I was trying to use #{Bindings.IteratorName.AttributeName.inputValue} to reference the value but it failed, since it is not the way it should be referenced. It is a attribute of the active Iterator binds to the table so simply it should be using the attribute binding. When drag and drop the view object to be exposed as an ADF table, the pageDef file adds the treeBinding as the Binding type for the table. So if we need to reference the value in the table, we need to create an attributeBinding, and simply reference its value by using EL: "#{Bindings.AttributeName.inputValue}".

Also we can reference it in Java. My previous post did this by utilizing the automatic binding of the UI component in a managed bean, by calling the method getSelectedRowData() or getValue() on the ADF table. Here I demonstrate just by calling the getControlBinding("IteratorName") from the Binding Container. In the method, I pass the name of the view object iterator in the data control that binds with the ADF table. Actually calling getControlBinding() from BindingContainer or getValue() from the binding table component did the exact same thing behind the scene.

Here is the code in Java:

Friday, September 17, 2010

About ClientListener and ServerListener

ClientListener, by its meaning, is fired/triggered by its source component to execute some client side script been defined in java scripts. Oracle defines it as "The clientListener tag is a declarative way to register a client-side listener script to be executed when a specific event type is fired. This tag will be ignored for any server-rendered components, as it is only supported by rich client components."
Before using the clientListener tag, be sure to look for any existing behavior tags which might eliminate the need for scripts. ClientListener is more generic and could be used anywhere there is a need for java scripts insertion. But ADF already provides some specific tag listener for some special occasion,  for example: the af:showPopupBehavior tag simplifies what it takes to display a popup.

This example will invoke the JavaScript method "showPopupFromAction" when the button is clicked and will then manually display a popup.

ServerListener, is fired/triggered by a custom client event to execute some server side actions. Oracles defines as "The serverListener tag is a declarative way to register a server-side listener that should be executed when a custom client event is fired. This tag will be ignored for any server-rendered components, as it is only supported for the rich client. The target method must return void and take one argument, a ClientEvent object."

The server side actions could be defined in a managed beans supporting the source components of the server listener. So the actions could be just a view layer action or it could be a method defined in business components (Application Module or View Objects) and exposed to client data control.

To fire a custom event from the client, use the AdfCustomEvent.queue() Javascript method. The Javascript having AdfCustomEvent.queue() should be called by the ClientListener, and AdfCustomEvent.queue() method is calling the server side action defined in ServerListener.

The AdfCustomEvent.queue() JavaScript method enables you to fire a custom event from any component whose clientComponent attribute is set to true. The custom event object contains information about the client event source and a map of parameters to include on the event. The custom event can be set for immediate delivery (that is, during the Apply Request Values phase), or non-immediate delivery (that is, during the Invoke Application phase).

For example, in the File Explorer application, after entering a file name in the search field on the left, users can press the Enter key to invoke the search. As Example 5-12 shows, this happens because the inputText field contains a clientListener that invokes a JavaScript function when the Enter key is pressed.

The JavaScript contains the AdfCustomEvent.queue method that takes the event source, the string enterPressedOnSearch as the custom event type, a null parameter map, and False for the immediate parameter.
The inputText component on the page also contains the following serverListener tag:
Because the type value enterPressedOnSearch is the same as the value of the parameter in the AdfCustomEvent.queue method in the JavaScript, the method that resolves to the method expression #{explorer.navigatorManager.searchNavigator.searchOnEnter} will be invoked.

Reference:
ClientListener
SeverListener
Sending custom event from client to the server

Wednesday, September 15, 2010

"Undo changes" Java codes

To implement a cancel edit button on an view object iterator which has changed data in cache, simple java codes can be used. The script is extracted from Frank's ADF code corner series 06 - "How to cancel an edit form, undoing changes in Java".

The script is put in the managed bean of the cancel button, either in ActionListener or Action beans. The example is in the ActionListener.