Wednesday, May 23, 2012

Difference Between Render and Visible property of component in adf

Difference between Render and Visible property of component:

In this post i would  like to  explain difference between Render and Visible

Render property decide whether  this component need  to render on UI or not.Or whether this component added into tree model or not.

Moreover all ADF component will render into html.if we put render false on any component then in this case ADF render kit is not going to create the html code for that component.and  since no html code generated  so that  this component is not going to participate in ADF/JSF life cycle.

Visible is same as Render but it differ slightly.If the visible if false still html code will generated from render kit and also it is going to participate in life cycle even though it is not  visible.

The following use case will explain the situation where we need to bit caution if we are using visible false and require true at same time .

Suppose you  have one UI page which  contains more than 10-20 components.But by mistake you make one component as visible false and require true.And if  you  are submitting  the form then in this case it is not going to submit the form because on the process validation phase the validation is failing so the life cycle is advance to render response and same time also it is not reporting any error message on UI.

Apart from this also we do not have any clue why page in not submitting.Because it is client side validation and internally it is throwing error message but component it self is not visible so how it will show error message on UI.

Property Render (true) Render (false) Visible (true) Visible (false)
Html Code Generation Yes No Yes Yes
Participating in life cycle Yes No Yes Yes
Required validation Yes No Yes Yes
Coming on UI Screen Yes No Yes No

Practical Explanation : 

For  Explaining above scenario i have created one page which contains following code

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1">
      <af:form id="f1">
        <af:panelFormLayout id="pfl1">
          <af:inputText label="RenderComponent" id="it1"
                        binding="#{backingBeanScope.backingBean.renderComponentBinding}"/>
          <af:inputText label="VisibleComponent" id="it2"
                        binding="#{backingBeanScope.backingBean.visibleComponentBinding}"/>
          <af:commandButton text="Next Page" id="cb1"
                            actionListener="#{backingBeanScope.backingBean.renderComponentActionListener}"/>
        </af:panelFormLayout>
      </af:form>
    </af:document>
  </f:view>
</jsp:root>

if you run the project and i you have fire bug install on Mozilla then you can see the following htnl code :


And if you make first input text component as render false.and  run the page then in this case if you see the html code through fire bug it does not have html code for that.

And if you make second component as visible false and run the page then in this case you can see the html code of this component.

Last point but this is very importance point .

if you make second  component  visible false and require true and try to submit. It will not navigate you to on second page because require validation if failed of second component.

But we have one option to see the require message and that option is

 <h:messages id="m1"></h:messages>

put this code on the page and run  the page .And if you click on the button it will  show global message on the page saying require validation is failed.









I hope it would be help full.

Thanks
Prateek






Sunday, May 20, 2012

Multiple DataBinding.cpx files in ADF 11 g?

The Answer is yes .in 10 g it is not possible but in 11 g  it is possible. If any Application contains more than one data binding than entry should be added into adfm.xml
The following code is code of adfm.xml file.
<?xml version="1.0" encoding="UTF-8" ?>
<MetadataDirectory xmlns="http://xmlns.oracle.com/adfm/metainf%22%3Cbr />                    version="11.1.1.0.0">
  <DataControlRegistry path="soadev/ext/DataControls.dcx"/>
  <DataControlRegistry path="soadev/ext/DataControlsHelper.dcx"/>

</MetadataDirectory>

Saturday, May 19, 2012

Exception Handling in adf (Part 1)


Exception Handling in ADF

Since Exception handling is very vital part of any web based application and technique of exception handling implementation  is depend on from where it is throwing.
The exception will occurred on following part of the application

1-Model
2-View Controller

It may be Model layer or may be View layer

Moreover the Exception handling approach is base on the layer from where it's thrown .If it is throwing through Model layer then the way of handling is difference compare to if it thrown on the View Controller .

As you all know we are accessing model layer through the binding container. Internally If any exception has thrown by model layer ,then by default the DCErrorHandlerImpl class going to catch the exception and show the  error message to user.(this is default features of ADF).

In some case we do not want to show the exception because as end user they want more specify message.So in this case we need to override default exception .

So first i would like to explain exception handling approach in model layer


Following step will explain the way of exception in model.

1-Create the class and extends with DCErrorHandlerImpl
2-Override the public void reportException(DCBindingContainer bc, Exception ex) .

According your requirement report the exception on DCErrorHandlerImpl.

package com.prateek.blog.view.exception;

import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCErrorHandlerImpl;

import oracle.jbo.JboException;

public class CustomExceptionHandler extends DCErrorHandlerImpl {
    public CustomExceptionHandler() {
        super(true);
    }

    @Override
    public void reportException(DCBindingContainer dCBindingContainer,
                                Exception exception) {

        if (exception instanceof JboException) {
            //By default all exception which are coming from Model layer all are instance of JboException
            //here just i am try to skip the exception to report to super class which is DCErrorHandlerInpl
            //we can write our own logic
            // if the exception came of model then it always go through this if condition
        } else {
            super.reportException(dCBindingContainer, exception);
        }

    }

    private void disableAppendCodes(Exception ex) {
        if (ex instanceof JboException) {
            JboException jboEx = (JboException)ex;
            jboEx.setAppendCodes(false);
            Object[] detailExceptions = jboEx.getDetails();
            if ((detailExceptions != null) && (detailExceptions.length > 0)) {
                for (int z = 0, numEx = detailExceptions.length; z < numEx;
                     z++) {
                    disableAppendCodes((Exception)detailExceptions[z]);
                }
            }
        }
    }

    @Override
    public DCErrorMessage getDetailedDisplayMessage(BindingContext bindingContext,
                                                    RegionBinding regionBinding,
                                                    Exception exception) {
        return super.getDetailedDisplayMessage(bindingContext, regionBinding,
                                               exception);
    }

    @Override
    public String getDisplayMessage(BindingContext bindingContext,
                                    Exception exception) {
        return super.getDisplayMessage(bindingContext, exception);
    }

    @Override
    protected boolean skipException(Exception exception) {
        return super.skipException(exception);
    }

}

*This is just a example to just skip the exception.Please see the following link for more information.

1-http://docs.oracle.com/cd/B31017_01/web.1013/b25947/web_val008.htm

3-After Creating our own custom exception handler we need to right this class in DataBinding.cpx as ErrorHandlerClass

<application clienttype="Generic" errorhandlerclass="com.prateek.blog.view.exception.CustomExceptionHandler" id="DataBindings" package="com.prateek.blog.view" separatexmlfiles="false" version="11.1.1.59.23" xmlns="http://xmlns.oracle.com/adfm/application">
  <pagemap>
    <page path="/exceptionPage.jspx" usageid="com_prateek_blog_view_exceptionPagePageDef">
  </page></pagemap>
  <pagedefinitionusages>
    <page id="com_prateek_blog_view_exceptionPagePageDef" path="com.prateek.blog.view.pageDefs.exceptionPagePageDef">
  </page></pagedefinitionusages>
  <datacontrolusages>
    <bc4jdatacontrol configuration="AppModuleLocal" factoryclass="oracle.adf.model.bc4j.DataControlFactoryImpl" id="AppModuleDataControl" package="com.prateek.blog.model" supportsfindmode="true" supportsrangesize="true" supportsresetstate="true" supportssortcollection="true" supportstransactions="true" syncmode="Immediate" xmlns="http://xmlns.oracle.com/adfm/datacontrol">
  </bc4jdatacontrol></datacontrolusages>
</application>

4-The following code which i have written in to backing bean  to show our custom message on UI.

    public void jboException(ActionEvent actionEvent) {
        BindingContainer bindings =
            BindingContext.getCurrent().getCurrentBindingsEntry();
        OperationBinding opeartionBinding =
            bindings.getOperationBinding("throwNewException");
        opeartionBinding.execute();
        if (opeartionBinding.getErrors().size() > 0) {
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message = new FacesMessage("Error message here");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(null, message);
        }

    }

    public void numberPointerException(ActionEvent actionEvent) {
        BindingContainer bindings =
            BindingContext.getCurrent().getCurrentBindingsEntry();
        OperationBinding opeartionBinding =
            bindings.getOperationBinding("throwNewException1");
        opeartionBinding.execute();
        if (opeartionBinding.getErrors().size() > 0) {
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message = new FacesMessage("Error message here");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(null, message);
        }
    }


And upcoming blog i will explain exception handling on task flow and exception handling as global.

This exception handling approach is not going to catch any exception which is thrown from UI

Thanks
Prateek Shaw



Friday, May 11, 2012

Missing IN or OUT parameter at index:: 1 in Adf

java.sql.SQLException: Missing IN or OUT parameter at index:: 1 in Adf

If the bind variable property wrongly defined into VO then it will cause following exception

"java.sql.SQLException: Missing IN or OUT parameter at index:: 1 "

If the Bind Variable' s  required property wrongly defined into VO.Then this will lead to missing in or out exception.To prevent this exception following thing you have to keep in mind when you are creating new bind variable.

We can use bind variable following way in VO

1-Direct in query
2-or in the view criteria.

 1-If you are directly passing the bind variable in query then in this case bind variable require property should be selected 



2-or if you are creating view criteria then in this case the bind variable property should not be  selected



Thanks
Prateek

Thursday, May 10, 2012

Performance Tuning In Adf Application (Part 3)

Following are some more point to make application performance tune.

3-If in your application number of concurrent user more then please do following change in AM configuration.
   Please follow the step
  1-Click on the AM xml file and select the Configuration
  2-Click on the new button
  3- One pop up will open then  go to Polling and Scalability  option
  4- Go to"Maximum Availability" property and change it on basis of your concurrent user requirement  for example 50 or 100.

The following image will depict the above points



4-If you are using adf security  in your application be sure it's  implemented properly.Because if the way of implements  is wrong then it will create  the LDAP over head.The communication with LDAP server also impart on performance. so the number of call with the LDAP server should be less.

5-We can also do  some necessary changes or check into web.xml to make application performance  faster

    1-org.apache.myfaces.trinidad.CHECK_FILE_MODIFICATION should be false
    2-org.apache.myfaces.trinidad.DISABLE_CONTENT_COMPRESSION should be false
    3-javax.faces.STATE_SAVING_METHOD should be client

javax.faces.STATE_SAVING_METHOD   always be client side no need to mention on server.

Reference link :

1-https://blogs.oracle.com/ATEAM_WEBCENTER/entry/adf_deployment_view_layer_tuning


Thanks
Prateek