Java view technologies and frameworks: Difference between revisions

Content deleted Content added
No edit summary
 
(19 intermediate revisions by 12 users not shown)
Line 1:
{{Short description|Programming language and libraries}}
'''Java view technologies and frameworks''' are [[web-based]] [[software libraries]] that provide the [[user interface]], or "[[Model–view–controller|view-layer]]", of [[Java (programming language)|Java]] [[web application]]s. Such [[application framework]]s are used for defining [[web page]]s and handling the [[HTTP]] [[List of HTTP header fields#Requests|requests]] (clicks) generated by those web pages. As a sub-category of [[web framework]]s, view-layer frameworks often overlap to varying degrees with web frameworks that provide other functionality for Java web applications.
 
Line 6 ⟶ 7:
{| class="wikitable"
|-
! Action-based frameworks:
| [[Apache Struts]], [[Spring Framework|Spring MVC]]
|-
! Component-based frameworks:
| [[Apache Click]], [[Apache Tapestry]], [[Apache Wicket]], [[JavaServerJakarta Faces]]
|-
! Web template systems:
| [[Apache Tiles]], [[SiteMesh]], [[Thymeleaf]]
|-
|}
 
* [[JavaServerJakarta Faces]] (JSF), [[Apache Tapestry]] and [[Apache Wicket]] are competing component-based technologies, abstracting the [[Stateless protocol|stateless]] HTTP request-response cycle and the [[JavaJakarta Servlet]] [[API]] behind an [[Object-oriented programming|object-oriented]], event-driven component model.
* In contrast, Struts and the [[Spring Framework|Spring MVC Framework]] are action-oriented frameworks that provide a thinner [[abstraction layer]] over the servlet [[API]].
* Apache Tiles is a templating framework designed to work with Struts.
* [[Facelets]] is a view definition and templating technology designed to work with JSF.
* [[SiteMesh]] can be used with any [[JavaServerJakarta Server Pages|JSPJakarta Pages]] (JSP).
* Facelets, Tapestry and Wicket have their own templating approaches based on [[HTML]]/[[XHTML]].
* [[Apache Click]] uses HTML based [[Apache Velocity]] templates and [[Plainplain Oldold Java Objectobject]]s (POJOs), with [[JavaServer Pages]]JSP optional.
 
==Servlet API==
{{main |Jakarta Servlet}}
 
The Servlet API is the foundation of almost all Java Web View technologies. ServletsServlet provides the basic mechanism for writing Java [[Classclass (computer programming)|classesclass]]es for web applications. Servlets can respond to HTTP requests, create cookies and maintain sessions.
 
==JavaServerJakarta Pages (JSP) ==
{{main |Jakarta Server Pages}}
* Built on top of the Servlet API, JSP provides for a document-centric, tag-based templates, server programming model which can generate many forms of textual content.
 
* Built on top of the Servlet API, JSP provides a document-centric, tag-based templates, server programming model which can generate many forms of textual content.
* Java code may be embedded in JSP files and is compiled and executed when a request is received.
 
==Apache Struts==
{{main |Apache Struts}}
* Struts provides for a [[Coupling (computer programming)|decoupling]] of the Controller and the View.
 
* Struts provides for a [[coupling (computer programming)|decoupling]] of the Controller and the View.
* Requests are received by a Java Class (Controller) which can decide which View to display.
* The actual View can be written in different view technologies, like JSP, free marker template, velocity template etc.
Line 41 ⟶ 47:
 
==Apache Tapestry==
{{main |Apache Tapestry}}
 
* A component-based view framework.
* Classes are written as POJOs and byte-code transformed at run timeruntime
* Configured with annotations and naming conventions rather than XML
* Compared to JSPs, enforces a clear separation of [[HTML element|HTML markup]] and Java code.
* HTML templates arecan be directly previewablepreviewed by web designers
* Changed component classes are live-reloaded into running application for faster development.
* Uses the [[Post/Redirect/Get]] navigation pattern for form submission.
* '''Competitor''': Wicket, JSF, HybridJava
 
==Apache Tiles==
{{see also |d:Special:EntityPage/Q28912908|l1=Apache Tiles}}
 
* This is an HTML templating framework based on the [[composite pattern]].
* It allows for the HTML page to be broken up into multiple "pagelets", called Templates, Definitions and Composing pages.
* At [[runtime (program lifecycle phase)|runtime]] the pagelets are stitched together to generate the final HTML. Pages are written in JSP.
* '''Competitor''': SiteMesh
 
==Apache Wicket==
{{main |Apache Wicket}}
 
* A component-based view framework.
* Pages directly interact with stateful Java components on the server.
Line 57 ⟶ 75:
* Compared to JSPs, enforces a clear separation of [[HTML element|HTML markup]] and Java code.
* Web page components are 'pushed' into the HTML markup from the code.
* '''Competitor''': Tapestry, JSF, HybridJava
 
==Jakarta Faces and Facelets==
{{main |Jakarta Faces}}
 
==JavaServer Faces (JSF) and Facelets==
* A specification for component-based view frameworks.
* [[Eclipse Mojarra]] and [[Apache MyFaces]] implementations are available
* Typically uses Facelets for XML/XHTML-based templating.
* Classes are written as POJOs, with Annotations or XML configuration files used to associate them with page and component templates.
Line 71 ⟶ 91:
 
==SiteMesh==
{{main |SiteMesh}}

* [[SiteMesh]] is an HTML templating framework based on the "Decoration" model.
* It allows for the creation of a 'decoration' template which is then applied to any other HTML to generate a new HTML.
* The newly generated HTML contains elements from the original HTML blended into the template.
Line 79 ⟶ 101:
 
==Spark==
*{{main [[|Spark (software) |}}

* Spark ]] is a micro web framework built around a simple routing system
* It runs on an embedded [[Jetty (web server)|Jetty]] web server by default, but can be configured to run on other webservers.
* It supports three different templates engines: [[Apache Velocity | Velocity]], [[FreeMarker]] and [[Mustache (template_systemtemplate system) | Mustache]]
* It aims to facilitate rapid development, and does not make use of annotations or proprietary solutions.
 
An example of a Java Controller program-
package com.accenture.adf.businesstier.controller;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
 
import com.accenture.adf.businesstier.entity.Event;
import com.accenture.adf.businesstier.entity.EventCoordinator;
import com.accenture.adf.businesstier.entity.Visitor;
import com.accenture.adf.businesstier.service.EventFacade;
import com.accenture.adf.businesstier.service.EventServiceImpl;
import com.accenture.adf.exceptions.FERSGenericException;
 
/**
*
* @author krishna.x.kishore This controller will handle all event related
* activities for a new visitor
*
*/
 
@Controller
public class EventController {
 
private static Logger log = Logger.getLogger(EventController.class);
 
/**
* @param request
* @param response
* @return
* @throws Exception
* The method will display all the events available in the
* catalog to the visitor
*/
@RequestMapping("/catalog.htm")
public ModelAndView getAvailableEvents(HttpServletRequest request,
HttpServletResponse response) throws Exception {
 
if (request == null || response == null) {
log.info("request or response not valid in GETAVAILABLEEVENTS METHOD ");
throw new FERSGenericException(
"Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder",
new NullPointerException());
}
 
List<Object[]> eventList = new ArrayList<Object[]>();
EventFacade serviceImpl = new EventServiceImpl();
eventList = serviceImpl.getAllEvents();
 
log.info("All Events are listed :" + eventList);
HttpSession hs = request.getSession();
Visitor visitor = (Visitor)hs.getAttribute("VISITOR");
ModelAndView mv = new ModelAndView();
mv.addObject("allEvents", eventList);
mv.addObject("visitor",visitor);
mv.setViewName("/eventCatalog.jsp");
return mv;
}
 
/**
* This method deletes the event from database
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping("/deleteEvent.htm")
public ModelAndView deleteEvent(HttpServletRequest request,
HttpServletResponse response) throws Exception {
 
if (request == null || response == null) {
log.info("request or response not valid in DELTEEVENT METHOD ");
throw new FERSGenericException(
"Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder",
new NullPointerException());
}
 
String eventId = request.getParameter("eventId");
String sessionId = request.getParameter("sessionId");
List<Object[]> eventList = new ArrayList<Object[]>();
EventFacade serviceImpl = new EventServiceImpl();
serviceImpl.deleteEvent(Integer.parseInt(eventId), Integer.parseInt(sessionId));
eventList = serviceImpl.getAllEvents();
HttpSession hs = request.getSession();
Visitor visitor = (Visitor)hs.getAttribute("VISITOR");
ModelAndView mv = new ModelAndView();
mv.addObject("allEvents", eventList);
mv.addObject("visitor",visitor);
mv.setViewName("/eventCatalog.jsp");
return mv;
}
 
/**
* This method displays the add/update event page
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping("/displayEvent.htm")
public ModelAndView displayEvent(HttpServletRequest request,
HttpServletResponse response) throws Exception {
 
if (request == null || response == null) {
log.info("request or response not valid in DISPLAYEVENT METHOD ");
throw new FERSGenericException(
"Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder",
new NullPointerException());
}
 
String eventId = request.getParameter("eventId");
String sessionId = request.getParameter("sessionId");
EventFacade serviceImpl = new EventServiceImpl();
List<EventCoordinator> eventCoordinator = serviceImpl.getAllEventCoordinators();
Event event;
if (eventId.equals("-1")) {
event = new Event();
event.setAdd(true);
} else {
event = serviceImpl.getEvent(Integer.parseInt(eventId),
Integer.parseInt(sessionId));
}
 
log.info("Displaying event for eventId:" + eventId);
HttpSession hs = request.getSession();
Visitor visitor = (Visitor)hs.getAttribute("VISITOR");
 
ModelAndView mv = new ModelAndView();
mv.addObject("event", event);
mv.addObject("eventCoordinator", eventCoordinator);
mv.addObject("visitor",visitor);
mv.setViewName("/addEvent.jsp");
return mv;
}
 
/**
* This method updates the event
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping("/updateEvent.htm")
public ModelAndView updateEvent(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String statusString = "";
if (request == null || response == null) {
log.info("request or response not valid in UPDATEEVENT METHOD ");
throw new FERSGenericException(
"Error in Transaction, Please re-Try. for more information check Logfile in C:\\FERSLOG folder",
new NullPointerException());
}
 
String eventId = request.getParameter("eventId");
String sessionId = request.getParameter("sessionId");
String eventName = request.getParameter("eventName");
String desc = request.getParameter("desc");
String place = request.getParameter("place");
String duration = request.getParameter("duration");
String eventType = request.getParameter("eventType");
String ticket = request.getParameter("ticket");
String isAdd = request.getParameter("isAdd");
Event updatedEvent = new Event();
updatedEvent.setEventid(Integer.parseInt(eventId));
updatedEvent.setEventtype(eventType);
updatedEvent.setName(eventName);
updatedEvent.setDescription(desc);
updatedEvent.setPlace(place);
updatedEvent.setDuration(duration);
updatedEvent.setSeatsavailable(ticket);
updatedEvent.setSessionId(Integer.parseInt(sessionId));
EventFacade serviceImpl = new EventServiceImpl();
int status = -99;
if(isAdd.equals("true")){
String eventCoordinatorId = request.getParameter("coordinator");
String eventSession = request.getParameter("eventSession");
updatedEvent.setEventCoordinatorId(Integer.parseInt(eventCoordinatorId));
updatedEvent.setEventSession(Integer.parseInt(eventSession));
updatedEvent.setAdd(true);
status = serviceImpl.insertEvent(updatedEvent);
statusString = "Event added Succesfully !!!";
}
else{
status = serviceImpl.updateEvent(updatedEvent);
statusString = "Event updated Succesfully !!!";
}
List<EventCoordinator> eventCoordinatorList = serviceImpl.getAllEventCoordinators();
ModelAndView mv = new ModelAndView();
 
if (status > 0) {
mv.addObject("REGISTRATIONSTATUSMESSAGE",statusString);
log.info(statusString);
 
} else if (status == 0) {
mv.addObject("REGISTRATIONSTATUSMESSAGE",
"There was error while saving the event. Please see log file for more details..");
log.info("There was error while saving the event. Please see log file for more details..");
}
 
mv.addObject("event", updatedEvent);
mv.addObject("eventCoordinator", eventCoordinatorList);
mv.setViewName("/addEvent.jsp");
return mv;
}
 
}
 
 
<!-- formatting; please do not remove until some more text lines are added to compensate spacing -->
 
==See also==
{{Portal|JavaComputer programming}}
* [[List of web service frameworks]]
* [[List of Java frameworks]]
 
==References==
* [[Java Servlet]] Technology (http://java.sun.com/products/servlet/)
* [[JavaServer Pages]] Technology (http://java.sun.com/products/jsp/)
* [[Apache Struts]] 2 Documentation (http://struts.apache.org/2.1.6/docs/home.html)
* Apache Tiles (http://tiles.apache.org/)
* [[Click Framework]] Project Documentation (http://incubator.apache.org/click/)
* Apache Wicket (http://wicket.apache.org/)
* [http://tapestry.apache.org/ Tapestry Home Page]
* [http://www.hybridjava.com/ HybridJava Home Page]
* [http://sparkjava.com/ Spark Home Page]
 
[[Category:Java (programming language)]]