Wednesday, September 23, 2015

How to create instance from generic type

It’s easy to explain this in code. public <T> void myMethod(List<T> list) { T t;// t = new T(); // This is basically what you want, // but will cause compile error. }Strictly speaking, you can NOT create instances of type parameters. But you can reach the same goal by using reflection and one more parameter. public <T> void myMethod(List<T> list,...

Tuesday, September 15, 2015

Asynchronous Spring MVC – Hello World Example

Asynchronous processing is supported since Servlet 3.0. Spring MVC makes asynchronous processing even simpler. Here is a hello world level demo on how to do that using Spring MVC. Basically there are 2 things need to do: configure web.xml to turn on async support return Callable instance  instead...

Monday, September 14, 2015

How to setup Spring MVC project with maven in Eclipse

There article shows how to create a spring MVC project with maven in Eclipse. The eclipse comes with an internal maven-archetype-webapp for webapps, but is somehow a little bit out of date. The project created by that needs some extra work to make it workable. In this demo a maven managed Spring MVC...

Friday, September 11, 2015

Using log MDC in multi-thread - Hello World example

The slf4j has MDC which will  delegate to underlying logging system's MDC implementation.  The most popular logging systems are log4j and logback. They both support MDC. So the most common way to use MDC (or logging system) is through slf4j API. In this demo, logback is used as underline logging...

Thursday, September 10, 2015

How to invoke an object’s private method in Java

The private methods are designed not accessible from outside. But sometimes we want to call it directly, for example in unit testing. Java actually provides ways to call private method with the help of reflection, java.lang.reflect.Method PowerMock, a widely used mock library also provide helper class to make it easy  in JUnit test cases. (PowerMock indeed wraps the reflection for you) In this...

Tuesday, September 1, 2015

HTML Tags for JavaServer Faces (JSF)

The HTML Tags in for JSF is mostly used tags when writing JSF page. They are listed here for quick reference. The table comes from oracle JEE7 documents here. Tag Functions Rendered As Appearance h:column Represents a column of data in a data component A column of data in an HTML table A column in a table h:commandButton Submits a form to the application An HTML <input type=value>...
Powered by Blogger.

About The Author

My Photo
Has been a senior software developer, project manager for 10+ years. Dedicate himself to Alcatel-Lucent and China Telecom for delivering software solutions.