Thursday 20 June 2013

ADF : Refresh issues in Oracle ADF Application

During the application development in ADF, the most common problem that we encounter when our application is deployed on server is the problem of refresh. That means you expect a component to refresh on some action but still it doesn't happens.

This problem comes into picture in a big size application that uses many other applications or many taskflows are being called into it.I dont exaclty know why this problem comes into focus, but its some kind of 'id' problem of UIcomponent. 

So, here are some of the solution if the above problem comes into picture.


  1. The easiest way to give partial trigger to a UIComponent is to go into the properties menu in the property inspector and simply choose the component id you want to select. So whenever the selected UIcomponents will have a change, the UIComponent on which partial refresh is given is refreshed.



     
  2. Sometimes it happens that even after giving partial trigger on the UIComponent the Component is not been refreshed.So, you can try to refresh the component from the bean using java code.
    AdfFacesContext.getCurrentInstance().addPartialTarget(UIComponent);


    Here 'UIComponent' is the binding of the UIComponent on the page into the bean.
  3. Sometimes the above two methods fail.After using the above two techniques also the field is not being refreshed. Then you can use the ResetUtil class for resetting the fields.

    For using ResetUtil you have to import the given class:
    import oracle.adf.view.rich.util.ResetUtils;
    

    And to use it on the page :

    ResetUtils.reset(UIComponent); 
      
  4. After using the above methods if Still the problem exists. Then if you are using model in your application, then you have to perform "execute" on the used ViewObject.
  5. Still if the problem persists, then perform "Rollback" after the "Commit" operation.
  6. Still if the problem exists, please drop your case in the comment box.. :) 

Wednesday 19 June 2013

ADF : Disable and Enable TableSelectionListener

Some times in the development we need to enable or disable the table so that the user is not able to make row selection from the table.
Suppose there is a case in which a row selected in the table is in edit mode in a form, and you don't want to allow the user to select any other row during the edit operation. So for this purpose you need to disable the table selection.
You can use the following code for doing so :



tableBinding.setRowSelection(RichTable.ROW_SELECTION_NONE);

Here :
  1.  "tableBinding" is the binding of table in the bean. 
And after your work when you want to again enable the rowSelection. You can use it as follows :
tableBinding.setRowSelection(RichTable.ROW_SELECTION_SINGLE);

Tuesday 11 June 2013

ADF : Running or calling javascript from java bean

In the other post of mine I wrote about the steps to call Java method from a javascript code. Now I am gonna tell you how we can call a Javascript code from Java code. This is the easiest method I found on the internet.
  1. For calling Javascript you have to use the following method in the java bean :

    public static void runJavaScriptCode(String javascriptCode) { 
             FacesContext facesCtx = FacesContext.getCurrentInstance(); 
             ExtendedRenderKitService service =
    Service.getRenderKitService(facesCtx, ExtendedRenderKitService.class); 
             service.addScript(facesCtx, javascriptCode); 
           } 



    You have to import the following packages :
    import javax.faces.context.FacesContext;
    import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
    import org.apache.myfaces.trinidad.util.Service;
  2.  And to call the javsccript from the java code :
    runJavaScriptCode("alert(\"My name is Java\");");

ADF : Calling Java code from JavaScript

There are occassions on which we need to call Java code that resides in the bean from the client side script i.e. Javascript. Here are the steps to do so.

  1. Use the given code to create a inputtext component in ADF page. You need to add a clientListener and a serverListener as given in code snippet.

    <af:inputText label="Label 1" id="it1">
                        <af:clientListener type="keyUp" method="handleBlur"/>
                        <af:serverListener type="MyCustomServerEvent" method="#{DateBean.handleServerEvent}"/>
                    </af:inputText>

    <af:resource type="javascript">
                    function handleBlur(evt) {
                   
                    var inputTextComponent = evt.getSource();
                    AdfCustomEvent.queue(
                            inputTextComponent,
                            "MyCustomServerEvent",{fvalue:inputTextComponent.getSubmittedValue()},
                            true
                            );
                            evt.cancel();
                    }
    </af:resource>


    • Here the code var
      " AdfCustomEvent.queue(inputTextComponent,"MyCustomServerEvent",{fvalue:inputTextComponent.getSubmittedValue()},true); "

      is like


      AdfCustomEvent.queue(
      Source component
      ,
      the type defined in servetlistener
      ,
      key value pair,
      immediate(
      true or false)
      );
  2. Now create a class that will contain the method that is called from the javascript. Here i have named it DateBean.
    And create a method as shown.

        public void handleServerEvent(ClientEvent ce){
            String message = (String) ce.getParameters().get("fvalue");
            System.out.println(message);
    }
  3. Now run the code. The server side java method is called on onblur event on the input field.