Pages

Monday, March 31, 2014

Showing Error Message programmatically

How to show error message programmatically


ADF Faces uses the standard JSF messaging API. JSF supports a built-in framework for messaging by allowing FacesMessage instances to be added to the FacesContext object using the addMessage(java.lang.String clientId, FacesMessage message) method. 

Error Message can be shown inline using af:messages and setting inline property to false.

Code to show error Message :

Following types of error messages can be shown : 


Component-Level Message : 
These messages are associated to a specific component based on the clientID parameter passed to addMessage method. 

Global-Level Message : 
These messages are not associated to any component and null is passed for clientID parameter to addMessage method. 

Sample app can be download from here Enjoy !!!

Tuesday, March 18, 2014

ADF Logging Explained Chapter 4

ADF Logging Explained Chapter 4

In this post, we tried to cover the commonly used methods of ADFLogger class.

Now I create ADFLogger instance and try to log a message using belowCode : 

private static ADFLogger logger = ADFLogger.createADFLogger(TestLoggerTFBean.class);
logger.log("Logging Message1");

After running the application, I set the LogLevel of my custom ADFLogger to Warning. Now lets see the logged message ...it's not there. Why ? We created ADFLogger instance... logged the message ... set the LogLevel ... and no message Logged. 

Almost all logging methods internally does a check isLoggable before logging. The above logger.log method checks isLoggable(ADFLoggerLevel.TRACE) and which return false because our custom ADFLogger's LogLevel is Warning. 

Lesson Learnt : Information about internal LogLevel check is required before using any log method.

Well not to worry... other log methods are straight forward. Here are some examples : 

logger.severe(String msg)  - This checks isLoggable against Level.Severe.
logger.fine(String msg)  - This checks isLoggable against Level.Fine.
logger.log(Level level, String msg) - This check isLoggable against inputParameter level before logging.


That's it. Enjoy logging.

If you want more than this, please go Adventures in Logging index by Duncan Mills. 

Monday, March 10, 2014

ADF Logging Explained Chapter 3

ADF Logging Explained Chapter 3

This post illustrates ADFLogger initialization concepts.

First thing you create the ADF Logger instance using below code  :

  private static ADFLogger logger = ADFLogger.createADFLogger(TestLoggerTFBean.class);

Log Level for newly Created Instance

I ask you a very simple question : Say you have not done any additional change to Oracle Diagnostic Logging. That is it looks like this :


Now What is the logLevel for the above ADFLogger instance "logger" ?

Answer is LogLevel is null.

How isLoggable(Level level) check works on logger instance with LogLevel null ?


Ahh...Now we know that LogLevel is null for a newly created ADFLogger instance when it is not configured in OracleDiagnostic Logging.  Wondering what will happen to code comparing LogLevel before logging any info ?  Like :

        if(logger.isLoggable(ADFLogger.INTERNAL_ERROR)){
            logger.log("loggingBtnAction logger.isLoggable(ADFLogger.INTERNAL_ERROR) -> logger.log ");
        }

Well ADFLogger is based on java.util.logging.Logger and isLoggable method works on class variable levelValue [ private volatile int levelValue ] defined in java.util.logging.Logger . When a new ADFLogger instance is created, levelValue variable is update using the below logic :
So if LogLevel for logger is null it means that logLevel is inherited from the parent. As the logger build a tree, it picks the logLevel of parent till it reaches the logger which returns a level not null.

From java.util.logging.Logger
private volatile int levelValue;  // current effective level value

Thanks to Timo Hahn for clarifying this on https://community.oracle.com/thread/3524267




Thursday, March 6, 2014

ADF Logging Explained Chapter 2

Logging in ADF Application

 
For ADF Logging Explained Chapter 1, click here. This post describes Logging Levels.

Why there is need to learn Logging levels ?
When adding logger to Oracle Diagnostic Logging, there is option to define the loggingLevel for that Logger. Switching the logging Level in Oracle Diagnostic Logging for our custom Logger, you can control the level of details logged. Too much of logging can also cause performance issue. Decision of logging an information is taken based on the intValue comparision ( more details explained in later section ).


 A logging Level is defined using name,intValue and resourceBundleName. The resource bundle name to be used in localizing the level name so for now we will focus on name and intValue. There are some predefined Levels mentioned in java.util.logging.Level class.
 
LOG LEVEL NAME INT VALUE
OFF OFF INTEGER.MAX_VALUE
SEVERE SEVERE 1000
WARNING WARNING 900
INFO INFO 800
CONFIG CONFIG 700
FINE FINE 500
FINER FINER 400
FINEST FINEST 300
ALL ALL Integer.MIN_VALUE
 
Other logging Level types are custom levels defined using java.util.logging.Level with new name and API. 

Logging Levels defined in ADFLogger :

LOG LEVEL NAME INT VALUE
INTERNAL_ERROR INTERNAL_ERROR 1100
ERROR SEVERE 1000
WARNING WARNING 900
NOTIFICATION INFO 800
TRACE FINE 500
 
Other Logging Levels :
A) ODL Log Level
B) JAVA Log Level
C) Weblogic Server

 
 Here is detailed list of different logging levels and there comparision :



ODLWebLogic ServerJava
OFFOFF2147483647 - OFF
INCIDENT_ERROR:1(EMERGENCY)1100
INCIDENT_ERROR:4EMERGENCY1090
INCIDENT_ERROR:14ALERT1060
INCIDENT_ERROR:24CRITICAL1030
ERROR:1(ERROR)1000 - SEVERE
ERROR:7ERROR980
WARNING:1WARNING900 - WARNING
WARNING:7NOTICE880
NOTIFICATION:1INFO800 - INFO
NOTIFICATION:16(DEBUG)700 - CONFIG
TRACE:1(DEBUG)500 - FINE
TRACE:1DEBUG495
TRACE:16(TRACE)400 - FINER
TRACE:32(TRACE)300 - FINEST
TRACE:32TRACE295



Now you know about different available logging Level Types and their values. It is very much clear from the level names ALL and OFF that more and more detailed logging will happen with decrease in logging level int Value.





 

ADF Logging Explained Chapter 1

Logging in ADF Application


This post talks about using ADFLogger in adf application. The ADFLogger is a logging mechanism which is built into the ADF framework. It is built on top of java.util.logging API.

Using ADFLogger :

To start with you need to define the ADFLogger instance in your class ... something like below code :


public class TestLoggerTFBean {
    public TestLoggerTFBean() {
        super();
    }
    private static  ADFLogger logger = ADFLogger.createADFLogger(TestLoggerTFBean.class);

There are additional methods available in ADFLogger API to create ADFLogger instance. For other methods please refer to ADFLogger JAVA API.

Where to View Available Loggers :

Run your integratedWeblogic server and choose "Configure Oracle Diagnostic Loggin" from Actions. You will able to see all available loggers in the logging.xml file.


Registering your ADFLogger :

You can register your logger by clicking green plus "+" icon in right on logging.xml. You can choose to add transient (discarded at the end of session ) logger or persistent (stored in logging.xml) logger.

OR

When you run your application, you might notice that logger gets registered as when it is initialised.
 
In the sample app provided, there are two taskflows : 1) noLogger-tf 2)testLogger-tf . An ADFLogger instance in created in pageFlowScope managed bean for testLogger-tf. Running the TestLoggerPage.jspx loads the noLogger-tf ( Not ADFLogger instance created yet ). If you notice registered loggers, our custom logger "TestLoggerBean " is still not registered.
 
Click the button to navigate to testLogger-tf taskflow. Click button "Do Some Logging" to log something. Now again check available loggers and our custom logger is available.