Tuesday, November 29, 2011

Fixing the focus on the field, post validation on tab out event.

Recently I got a query on how to keep the focus on a text field after the field has been validated on tab out event occurrence. There are two ways to achieve the same as described below. The second one has been preferred by few people.  But I would anyways describe both of them.

1.Declare the validator method in the managed bean (autosubmit set to true, immediate set to true) also apply client listener on the input text. Replicate the validation done in the managed bean in the javascript method and use AdfFocusUtils.focusElementDelayed()  method to lock the focus.

2.In the value change listener if you are not throwing a ValidationException then you might also try calling the javascript method (having use AdfFocusUtils.focusElementDelayed()  method to lock the focus) using the ExtendedRenderKitService to achieve it.

Event handling for single record in ADF Table.

Scenario: The scenario is, that in the ADF table, when there is a single record, then it comes auto selected and no click event happens there after on the table row.

Solution approach: To use adf component to specifically handle the row selection event over the auto selected row.

Solution:
Add a client listener to the adf table tag by dragging and dropping the clientListener component from the Operations in the Component Palette. Add the method name (of the javascript method which will call the popup in turn). Also give the event name as click. After this add the below code snippet to call the popup defined on the jspx page.

<af:resource type="javascript">
        function showPopup()
       {
          var popupId = "p1";
          var popup = AdfPage.PAGE.findComponentByAbsoluteId(popupId);
          popup.show();
        }
</af:resource>

Also, this solution could be used to call the server listner, by calling the javascript method using the clientListener as described above. then use the AdfCustomEvent.queue() method to call the serverListener (again a component from the Operations in the Component Palette), which in turn declares the managed bean method that needs to be called.