Saturday, May 19, 2012

How to update the Log4J logger level dynamically for a web application?


Are you looking for an option o update the Log4J logger level dynamically for a web application? If so, here is the solution for people like you to update the logger which doesn’t require any log4j,xml file configuration change or serve restart.

Here we had developed a jsp page that will show the current loggerName, loggerlevel and the list of logger levels lits it can take. Now, you can select the new log level from selectbox to set the new logger on the fly.

Here is the code sample. Wanna try?


<%@ page import="org.apache.log4j.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Dynamic Log4J control
<%
            Logger logger = Logger.getRootLogger();
            logger.setLevel(Level.toLevel(
                                    request.getParameter("selectedLevel"), Level.INFO));
%>


           

                       

           

           

                       

                       

                       

           

           

                       

                       

                       

           


                       

Dynamic Log4J control


                       
Current Log Level Logger Name Set New Log level
${rootLogger.level} ${rootLogger.name}

Friday, April 13, 2012

Ear comparator


Many Occasions, we might end up with comparing two ear/war files in our project for some reasons. Here is the link for EAR comparator utility (Good stuff Joseph! – The mastermind behind this tool). You may think it will be good if you have some utility to compare such circumstances.

I have link below for ear files comparator utility. I strongly recommend this tool to make your job easier. 


Anymore suggestions? Drop those in comments section.

Cheers,
-NjN

Sunday, April 8, 2012

To start work with Maven (more than a build and deploy tool)


So far I have used ant as a build tool in all my projects. When I recently gone through the articles, found Maven used widely in most of the Java/J2EE applications. I tried to install maven in my machine recently. But found many issues and it was very difficult to follow the setup to complete my very first build.

I have found an excellent material to work with Maven. It has step by step guide with the screen prints. I found the below link is very interesting to follow. Hope this will useful to you as well.


Friday, April 6, 2012

How to work with browser specific Style sheets

If you would have worked with web applications I am sure you might had difficult time to deal with applying the style sheets specific to browser and its’ version.
Have found nice information on applying the browser specific style sheets recently.  Wanted to share with you guys.
Below article explains very well on conditional based approach (browser & version) to apply the different CSS files. This is most commonly used approach as well. 

CSS cross browser selector comes with noticeable approach, where we no need to write different CSS files. Within the same CSS file we can mention the style classes based on the brower&version.

The second will be most preferable if we have css file with lesser contents. What do you think?

Monday, March 19, 2012

Java Anti Patterns:


I had gone through core java design patterns last week (I am sure I will consolidate my learning with simple examples and post you in my blog. I will try to keep as much as my own examples).

We have a proverb in our native language that “If you wanna become good doctor, you should have killed 100+ patients”. What they try to say here is if we want to give the best, we should have experience/come across as many nastiest.  

So, before I start my Java design patterns, I had gone through few Java Anti patterns which are readily available in the internet. I found the below link gives you Insite on Java Anti patterns. Hope you enjoy as well.

Please share me if you find any good link for Java Anti patterns.

http://www.odi.ch/prog/design/newbies.php

Friday, March 2, 2012

To get the newly stored record auto generated key (primary key) with in hibernate


I have seen few hibernate (ORM framework) codes have always uses saveOrUpdate method to create a record newly or to update the existing records. Most of the occasions, we were dam sure that a new record is gonna insert. Such occasions, we can use save method itself. No harm.  

Here I am going to discuss some peculiar scenario where we may need to get the primary key of the newly added record to send as a response to UI.

For Example, I am capturing required employee details and creating a new Employee record. Usually we used to display feedback as Info message in the screen stating “Employee record has been added successfully. as a response. Sometime we may need to display meaningful info message using the generated unique key for newly created record like “Employee record (1000001) has been added successfully.” Here, 1000001 is the primary of the newly inserted record.

To address the above requirement, I have seen few codes (mostly written by beginners), they used to call the save command (insert query) and use another select statement which gets you the recent record primary key column. It may work fine for the single user/thread environment. The same may not be true for multi thread environment. To address this issue in a multi threaded environment, below code may be useful for you to achieve the same.

Here, employeeObj is the hibernate object POJO for Employee Table. If we use hibernate save command, which will intern returns you the Serializable interface can cast to the primary key of the newly inserted record like below.  


//Plain Hibernate
Serializable t_pk  = t_session.save(employeeObj);

//Hibernate with Spring framework
Serializable t_pk  = getHibernateTemplate().save(employeeObj);


Long newEmployeeId = (long) t_pk  ;


Any thoughts? Please drop your comment.  


Cheers,
-NjN

Sunday, February 26, 2012

To read Window’s close button event using java script for application specific processing like session clear etc.


We are in very rapid technology transition world. Writing an application which is comparable to all the browsers and environments will be a tedious task for the developers like me.

Let me write a common & interesting issue with the web application session handling. While developing the web application, we will be clear about the scope of the variable to be used with in a web application (Like application, Session, Request and page scope etc). The entire logged in user specific details usually will be stored as session attributes. If we clear all session attributes, prior to closing the web application, its fine. No Harm. The same can be turned to be a headache if HttpSession was not handled properly. However if you use IE6, browser session automatically collected. In IE7, the same session will be used irrespective of the tabs opened within a browser instance. For IE8, same session will be used for all the browser/tab instances opened in a machine.

In a typical web application, we will be providing a Close/LogOff kind of buttons, so user could follow some basic process to exit the web application, using the button, we can handle the HttpSession. Also, we can’t assume that everyone would follow the process (It’s like turning off the PC. Sometimes we used to press the power button instead of shut down our PC). Now, the question is how can we handle, user session attributes such occasions as well.

Below example is self explanatory to address the above mentioned issue specifically for IE. Write to me if anything unclear.



Pega Decisioning Consultant - Mission Test Quiz & Answers

The Pega Certified Decisioning Consultant (PCDC) certification is for professionals participating in the design and development of a Pega ...