July 26 2016

Spring JdbcTemplate batchupdate example

Spring JdbcTemplate batchupdate example

Batch update option allows us to submit multiple queries to database at once. Spring JdbcTemplate supports batch updates through JDBC Statement and PreparedStatement. The Spring JdbcTemplate provides following overloaded methods for batch updates

int[] batchUpdate(String[] sql) throws DataAccessException

Executes multiple SQL queries on a single JDBC Statement

int[] batchUpdate(String sql, BatchPreparedStatementSetter pss) throws DataAccessException

Executes multiple SQL queries on a single PreparedStatement

The batch update support is introduced in JDBC 2.0.If your driver does not support batch updates then the above methods executes the queries as separate updates on single JDBC Statement and PreparedStatement.

Example Continue reading

Category: Spring | LEAVE A COMMENT
July 15 2016

Spring AOP AspectJ annotation example

Spring AOP AspectJ annotation example

Spring AspectJ provides annotation support for Spring AOP. AspectJ automatically generates proxy for the bean to intercept method invocations as configured.

How to enable @AspectJ support?

If you are using xml configuration file include <aop:aspectj-autoproxy/>

<aop:aspectj-autoproxy/>

If you are using configuration class add @EnableAspectJAutoProxy annotation Continue reading

Category: Spring | LEAVE A COMMENT
July 14 2016

Java compareToIgnoreCase example

Java compareToIgnoreCase example

The method ‘compareToIgnoreCase’ compares two strings ignoring case differences. It is similar to the ‘compareTo’ method, ‘compareTo’ method compares two strings with respect to case.

Syntax

int compareToIgnoreCase(String str)

Return type

The return type of the method is integer. If the return value is

  • >0 current string is greater than input string
  • =0  both the strings are equal
  • <0 current string is less than input string

Example Continue reading

July 1 2016

javax faces project stage configuration

javax faces project stage configuration

If you are working with JSF project, you should enable the ‘PROJECT STAGE’ for better performance. Project stage in JSF can be configured in web deployment descriptor file (web.xml) as context param.

<context-param>

<param-name>javax.faces.PROJECT_STAGE</param-name>

<param-value>Development</param-value>

</context-param>

The possible Project Stage values are Continue reading

Category: Jsf | LEAVE A COMMENT
June 23 2016

Jsf download file example

Jsf download file example


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">

<h:head>
<title> Jsf File Download </title>
</h:head>

<h:body>

<h:form>

<h3> Jsf File Download </h3>

<h:commandButton value="Submit" actionListener="#{jsfFileDownload.download}" />

</h:form>
</h:body>

</html>

Continue reading

Category: Jsf | LEAVE A COMMENT
June 16 2016

JSF managed property

JSF managed property is used to access one managed bean in other managed bean (Dependency Injection).Managed property can be configured using @ManagedProperty annotation or by adding <managed-property> to <managed-bean> in faces-config.xml

In the below example, ‘requestManagedBean’ managed bean have managed property for ‘verificationManagedBean’ managed bean

Note Continue reading

Category: Jsf | LEAVE A COMMENT
December 28 2015

Spring MVC Dispatcher Servlet

Spring MVC Dispatcher Servlet

Spring Web MVC framework is designed around the Front controller which is DispatcherServlet. DispatcherServlet is a servlet implemented as a subtype of HttpServlet. It is responsible for initializing the Spring Web MVC framework.

DispatcherServlet listens to the incoming requests and dispatches the request to handler,configurable handler mapping, view resolvers, local and theme resolvers. It has to be configured in web.xml Continue reading

Category: Spring | LEAVE A COMMENT
October 28 2015

Jsf interview questions and answers for experienced

JSF interview questions and answers for experienced

What is JSF?

JSF provides set of API’s which represents different UI Components and helps in managing state,handling events and validate user input. JSF is based on MVC architecture.

What are the different phases of JSF request processing life cycle?

There are six phases in JSF request processing life cycle

  • Restore View
  • Apply requests
  • Process Validations
  • Update model values
  • Invoke applications
  • Render response

Continue reading