Advantages of JSF


The major benefits of JavaServer Faces (JSF) technology are:

  1. JavaServer Faces architecture makes it easy for the developers to use. In JavaServer Faces technology, user interfaces can be created easily with its built-in UI component library, which handles most of the complexities of user interface management.
  2. Offers a clean separation between behavior and presentation.
  3. Provides a rich architecture for managing component state, processing component data, validating user input, and handling events.
  4. Robust event handling mechanism.
  5. Events easily tied to server-side code.
  6. Render kit support for different clients
  7. Component-level control over statefulness
  8. Highly ‘pluggable’ – components, view handler, etc
  9. JSF also supports internationalization and accessibility
  10. Offers multiple, standardized vendor implementations

Available implementations and Plugins of JSF?


JSF is the java specification given by the sun microsystems. For this specifications there are multiple;e implementations from the different third party vendors.  The main implementations of JavaServer Faces are:

  1. Reference Implementation (RI) by Sun Micro systems.
  2. Apache MyFaces is an open source JavaServer Faces (JSF) implementation or run-time.
  3. ADF Faces is Oracle’s implementation for the JSF standard.

The main Pluginsof JavaServer Faces are:

  1. Ice Faces FROM ICEsoft Technologies Inc.
  2. Prime Faces from Prime Technology.
  3. Rich Faces from JBoss
  4. Open Faces from TeamDevLtd
  5. DOJO Faces from DOJO

What is JSF?


JSF stands for Java Server Faces and it is an industry standard and a server side user interface component framework for building component-based user interfaces for web applications. JSF has set of pre-assembled User Interface (UI).

It is event-driven programming model. By that it means that JSF has all necessary code for event handling and component organization. Application programmers can concentrate on application logic rather sending effort on these issues. It has component model that enables third-party components to be added like AJAX.

Struts MVC


Struts is MVC based framework developed by Apache. Framework generally provides the basic functionality for a project. Struts provides the set of Action classes, set of tag-libraries, set of Form beans and etc.

Struts combines the most of the design patterns in to a single framework. Struts implements the Single-ton design pattern, Delegate design pattern, Factory Design pattern, Chain of responsibilities.

Struts is Strongly Model View Controller (MVC)based framework MVC fallows the three tier architecture. The model, view and controllers regarding to the Struts are explained as fallows.

View:

View is used to show something to user. Struts allows to use htmls, jsps as view components. To develop the more friendly views struts provided the set of tag libraries. You can download these libraries from the apache site and you can use those into your view components. The set of tag libraries are

struts-html : These tags are replacement of normal html tags. The struts html tags are binds with the form bean properties.

Ex: <html:text property=”userName” />

tag replaces the normal html tag like

<input type=”text” name=”userName” />

struts-bean : These tags are replacement for the jsp action tags. The bean properties are defined with this tags, you can get the bean properties using struts-bean tags.

Ex: <bean:define id=”tempVar” value=”10” />

Above tag defines a variable as ‘tempVar’ and assign 10 to it as string value.

<bean:write name=”Employee” property=”empId” />

Above tag get the value of empId from the Employee form bean.

Struts-logic: These tags are used to write the logical operations. To validate the if conditions or equals conditions you can use these tags.

Ex: <logic:equal name=”empId” value=”100” >Adimin</logic:equal>

Admin is displayed when the empId equals to 100 only.

To get the for loop type iterations you can use the <logic:iterate /> tag.

struts-nested: To display the group of objects you can use the nested tags.

You can implement most of the functionality of above three tags with the nested tags.

Inplace of <bean:write /> you have <nested:write /> and so on…….

Model:

Business logic and persistence logic (database dependent logic) will be developed in Model. In struts you can use normal Java beans, DTOs, Dos as models. You can develop the Model layer using other tools also. Struts allows to use Hibernate, spring in the model layer.

Controller:

Controller is most important concept in the Struts 1.3. In struts ActionServlet acts as Front controller. Each and every request must passes through the ActionServlet. You can change the ActionServlet functionality by extending ActionServlet to your own class.

RequestProcessor class also acts as the controller to process the request. In struts 1.3 Request processor is the ComposableRequestProcessor. It has processXXX() methods. These methods are controls the execution of action classes, controlling of form beans ..etc.

Actions, Dispatch actions, Action Forms , Validator forms ..etc all are come under the controller.

Difference Normal HTML tags and Struts HTML tags


Apache struts provided the struts html tags as the replacement of normal html tags for the Jsps. These Struts html tags are directly bind to the form bean using ActionForm where as normal html tags cannot bind with form beans. HTML tags are static but Struts tags are Dynamic (At the run-time struts tags are called)

But coming to performance half of the code in struts tags is pre-compiled one. If we use normal html tags web container has to load the jsp from the scratch. Where as struts tags loads with the pre-compiled code. So that struts tags improves the performance.

Struts 2


The core features of the struts 2 framework:

  1. Pluggable framework architecture that allows request life cycles to be customized for each action.
  2. Flexible validation framework that allows validation rules to be decoupled from action code.
  3. Hierarchical approach to internationalization that simplifies localizing applications.
  4. Integrated dependency injection engine that manages component life cycle and dependencies. (By default, the framework utilizes Spring for dependency injection.)
  5. Modular configuration files that use packages and namespaces to simplify managing large projects with hundreds of actions.
  6. Java 5 annotations that reduce configuration overhead. (Java 1.4 is the minimum platform.)

Struts 2 request Processing:

Each and every request made using struts 2 framework fallows the same request processing as below:

  1. Initially the web browser requests for request. (Ex: /index.acion or /myreport.pdf .. etc)
  2. The filter dispatcher looks at the request and determines the appropriate action.
  3. The interceptors automatically apply common functionality to the request, like work flow, validation, and file upload handling.
  4. The action method executes, usually storing and/or retrieving information from a database.
  5. The request renders the output to the browser, be it HTML, images, pdf, or something else.

The features added in struts2 over the struts1:

  1. Programming the abstract classes instead of interfaces is one of the design problem of struts1 framework that has been resolved in struts2.
  2. Most of the struts2 classes are based on interfaces and most of its core interfaces are HTTP independent.
  3. Unlike ActionForwards, Struts2 results provide flexibility to create multiple type of outputs.
  4. Actions in struts1 have dependencies on the servlet API since HttpServlertRequest and HttpServletResponse objects are passed to the execute() Method. But in struts2 any Java class with execute() method can be used as an Action Class. Actions to be neutral to the underlying framework
  5. ActionForms feature is no more known to the struts2 framework. Simple Java Bean flavored actions are used to put properties directly.
  6. Struts2 actions are HTTP independent and framework neutral. This enables to test struts2 applications very easily with out resorting mock objects.
  7. Struts2 tags enables to add style sheet driven markup capabilities.  ie. You can create consistent pages with less code. Struts2 tag markup can be altered by changing an underlying stylesheet.
  8. Struts tags are more capable and result oriented.
  9. Both JSP and Free maker tags are fully supported.
  10. Java 5 annotations can be used as an alternative to XML and Java properties configuration.
  11. Struts 2 check boxes do not require special handling for false values.
  12. Many changes can be done on fly without restarting the web container.
  13. Struts1 lets to customize the request processor per module. Struts2 lets to customize request handling per action if desired.
  14. Struts 2 Actions are spring aware. Just need to add spring beens.
  15. Struts2 extensions can be added by dropping in jar. No need of any addition XML or properties files. Metadata is expressed through convention and annotations.

Ajax support in Struts2:

  1. AJAX client side validation
  2. Remote form submission support (works with the submit tag as well)
  3. An advanced div template that provides dynamic reloading of partial HTML
  4. An advanced template that provides the ability to load and evaluate JavaScript remotely
  5. An AJAX-only tabbed Panel implementation
  6. A rich pub-sub event model
  7. Interactive auto complete tag

Struts1 and Struts2 at a glance:

Struts 1 vs. Struts 2

  1. Action                                    Action
  2. ActionForm                        Action or POJO
  3. ActionForward                  Result
  4. struts-config.xml              struts.xml
  5. ActionServlet                     FilterDispatcher
  6. RequestProcessor             Interceptors
  7. validation.xml                    Action-validation.xml