Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

JSF Versus JSP: Which One Fits Your CRUD Application Needs? (Part 1)

DZone's Guide to

JSF Versus JSP: Which One Fits Your CRUD Application Needs? (Part 1)

· Big Data Zone
Free Resource

Access NoSQL and Big Data through SQL using standard drivers (ODBC, JDBC, ADO.NET). Free Download 

We make decisions every day; everything we say and do is the result of a decision, whether we make it consciously or not. No matter how big or small is the choice, there's no (easy) formula for making the right decision. The best decision is the one you adopt after you approach the situation from as many perspectives as possible and then choose a course of action that seems reasonable and balanced at that time. 

This article aims to help those of you that were/are/will be challenged to choose between JSP and JSF for developing a CRUD application, all the words written inside it being accompanied by valid code snippets and samples.

Content of  JSF versus JSP debate consists of the following:


  • overview over the differences between the two technologies
  • architectural differences between applications developed with each of them
  • step by step implementation of an application with JSF/JSP ; the application(s) will be built over the same database and addressing  the same purpose.



Requirements:

  • an IDE

  • Java EE 6.0 or higher
  • Maven 2.0 or higher
  • JSF2.0 or higher


Differencies Between JSF and JSP

JavaServer Faces (JSF) is a web application framework that is based in Java. Its main objective is to simplify development integration of user interfaces that are web based. It is a request driven Model View Controller based on component driven UI design model, which uses XML –view templates or Facelet views. Requests ran through the JSF are processed by the FacesServlet. This component loads the view template that is required, builds a component tree, processes events, and renders the response –which is usually in HTML.


JavaServer Pages (JSP) is a Java based technology specifically used to help software developers serve dynamically generated web pages (such as HTML and XML) as well as other document types suitable to the development of interactive web content. It was specifically created in order to provide developers the ability to program  Java web applications.

JSF

JSP

JSF is a web application that is used to simplify development integration of web based user interfaces.

JSP is a Java based technology used specifically in order to help software developers create dynamic web pages.

JSF contains multiple core features, including, but not limited to, Managed Beans, a template based component system, and two XML based tag libraries.

JSP must be compiled in Java bytecode in order to function properly.JSP must be compiled in Java bytecode in order to function properly.

JSF is a framework.
Model:backing bean
View:JSF

Controller:facesservlet

JSP  is not a request driven model view controller, but JSP is accessed by the  dynamically generated web pages like HTML or XML.

JSF supports validator and conversion,ajax.

JSP does not.

Personal recommendations and observations:

1. Learn JSP first, and then JSF; you have to understand the past to see what future holds to you.  JSF is popular within nowadays applications implementations, but make sure you understand the components that make JSF a powerful tool.

2. JSP+Servlet are best suited for service-oriented applications  and need to control function of presentation through dispatching requests.

3. JSF and Facelet are more appropriate for generating mark-up like XHTML, and generally used for presentation-oriented applications.

4. JSF enables development of an web application with only model objects (JavaBeans) and views (JSP/XHTML pages).


5. In a JSP/Servlet  application the following will be necessary : a lot of code to control, preprocess, postprocess, gather data, validate, convert, listen, etc the HTTP request and response.

Architectural  Overview of Applications Developed with JSF and JSP

As a developer, before you start coding, you are responsible to examine the ways in which you can design the project. Specifically, you need to outline the responsibilities among functional components, and determine how they will interact with each other. As stated in the previous topic, both JSF and JSP have in common a the MVC (Model-View-Controller) paradigm so let's examine how an application that uses it is looking for each of them.


Adopting the MVC design pattern  for your application based on JSP (and not only) provides you with the following benefits:



  • Separation of design concerns: Because of the decoupling of presentation, control, and data persistence and behavior, the application becomes more flexible; changes  to one component have minimal impact on other components. New views can be created without needing to rewrite the model.
  • More easily maintainable and extensible code : Good structure can reduce code complexity. As such, code duplication is minimized.
  • Promotes division of tasks: Developers with different skill sets are able to focus on their favorite skills and collaborate through clearly defined interfaces.


When using JavaServerFaces2.0 or higher,  a request-response cycle goes through six lifecycle phases ( according to specifications), defined as follows:


  • Create or Restore View: Restores or creates a server-side component tree (View) in memory to represent the UI information from a client.
  • Apply Request Values: Updates the server-side components with fresh data from the client.
  • Process Validations: Performs validation and data type conversion on the new data.
  • Update Model Values: Updates any server-side Model objects with new data.
  • Invoke Application: Invokes any application logic needed to fulfill the request and navigate to a new page if needed.
  • Render Response: Saves state and renders a response to the requesting client.

The fastest databases need the fastest drivers - learn how you can leverage CData Drivers for high performance NoSQL & Big Data Access.

Topics:
bigdata ,jsp ,jsf ,data access ,java servlet 3.0 ,apache maven ,apache derby ,big data

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}