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

October 19 2015

Jsf setpropertyactionlistener example

Jsf setpropertyactionlistener example

Jsf ‘<f:setPropertyActionListener>’ tag creates a special action listener and registers with the associated action. It sets value specified by ‘value’ attribute to ‘target’ attribute.It is generally used in datatable to get the record selected by the user.

Attribute          Value expression
value                store the value of target attribute
target               defines the destination of value attribute

In the below example, the ‘stud’ property is set to student property of the studentBean. This will take place before editStudent method is executed. Continue reading

Category: Jsf | LEAVE A COMMENT
September 23 2015

Spring factory bean attribute

Spring factory bean attribute

A spring bean can be instantiated using non static factory method. A method that returns instance of a class is called factory method. The spring container uses the non-static factory method to instantiate the bean.

The bean of the factory method’s class has to be specified using ‘factory-bean’ attribute and the factory method name has to be specified using ‘factory-method’ attribute of the bean element.

<bean id=”employeeFactory” class=”com.answersz.factorymethods.EmployeeFactory” />

<bean id=”employeeService” factory-bean=”employeeFactory” factory-method=”getEmployeeService” />

Example Continue reading

Category: Spring | LEAVE A COMMENT
August 31 2015

Spring map injection

Spring map injection

The spring core container supports injecting the primitives, array, collections and spring bean through constructor or setter dependency injection.

A map can be injected using <map> element. A <map> element represents java.util.Map. A map can contain zero or more <entry> elements. Each <entry> represents one map entry. The <entry> element takes <key> and <value> elements.

Example

In the below example, countryMap is injected using setter dependency injection by placing the <map> element inside the <property>. The map can be injected using dependency injection by placing the <map> element inside <constructor-arg>. Continue reading

Category: Spring | LEAVE A COMMENT
August 27 2015

Spring factory method attribute

Spring factory method attribute

A spring bean can be instantiated using static factory method. A method that returns instance of a class is called factory method. The spring container uses the static factory method to instantiate the bean. The class name of the factory method has to be specified using ‘class’ attribute and the factory method name has to be specified using ‘factory-method’ attribute of the bean element.

<bean id=”employeeService” class=”com.answersz.factorymethods.EmployeeFactory” factory-method=”getEmployeeService” />

Example

In the below example, getEmployeeService is the static factory method in EmployeeFactory class which returns the instance of EmployeeService. The EmployeeService bean can instantiated by configuring class as ‘EmployeeFactory’ and factory-method as ‘getEmployeeService ‘.

EmployeeService.java Continue reading

Category: Spring | LEAVE A COMMENT
August 18 2015

Array of objects in java

Array of objects in java

Arrays are objects that can store multiple variables of same data type. The element of the array can be accessed using index number. The index of the array will always start from zero. If array’s size 5, the index will be from 0 to 4.

Array can hold either primitives or object references.If array is initialized the elements will get their default values, primitives will get the default values as per the data type whereas object references will get null.

 Array of Primitives

In the below example, marks is an array of primitives(int). Values can be initialized using index.

int[] marks = new int[5];

marks[1] = 10;

Array of Object References

In the below example, empArray is an array of Employee Object References. The Employee object reference has to be assigned to the array using index. Continue reading