In it's early days JSPs were misused for the realization of business logic. Any complex code enclosed in scriplets is hard to write, test and so maintain. However: JSPs are perfectly suitable for delivery graph paper of HTML 5 documents: You have full control over HTML markup. There is no hidden code generation in place. No magic: graph paper JSPs become Servlets. Usually you can even look at the generated code in case something feels strange. After the initial invocation, JSPs are as performant as Servlets. JSPs just serve strings, so no components have to be hold in memory -- the memory requirements are low. IDE support, debugging and performance analytics for JSPs are superb. JSPs even support lambdas in EL . JSPs can be perfectly used in the "logic free" mode, just as a powerful templating language. You can introduce custom tags for the encapsulation of recurring functionality. graph paper CDI managed graph paper beans and so whole Java EE components can be easily exposed to JSPs
A simple POJO: public class Greeting { private String title; private String content; public Greeting(String title, String content) { this.title = title; this.content = content; } public String getTitle() { return title; } public String getContent() { return content; } } Could be easily exposed by a CDI presenter / backing bean: @Model public class Index { public List<Greeting> getGreetings() { List<Greeting> greetings = new ArrayList<>(); greetings.add(new Greeting("short", "hi")); greetings.add(new Greeting("casual", "hello")); greetings.add(new Greeting("formal", "welcome")); return greetings; } } ...and conveniently rendered using a JSP: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <body> <h1>Hello JSP</h1> <ul> <c:forEach graph paper var="message" items="${index.greetings}"> <li><c:out value="${message.title}"/> - <c:out value="${message.content}"/></li> </c:forEach> </ul> </body>
Posted at 10:07AM Aug 06, 2014 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | Comments[14] | Views/Hits: 4725 Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014
Although syntactically similar, they are radically different. Clieny side frameworks distribute rendering cost to clients, in jsp it is all done in server. You have to do web services any way for 3rd party integration and mobile apps. JS model makes decoupling of model and view more obvious.
Client side frameworks graph paper are OK for lightweight applications (by lightweight I do not mean simple) however they are not a replacement for things like RIA's where JSF/JSP are a better fit. Having Session data on the client is definitely not a valid argument in favour of client side frameworks either, you can get that with JSF too. The expense comes in maintaining that state which with JSF is done for you. Anything based on client side scripting will become increasingly difficult to maintain and extend as the size of the project grows too. I advocated using the best tools for the job, avoiding any ideological graph paper argument in favour of pure pragmatism.
I share the feeling that jee front end alternatives didn't follow html evolution. Even though jee wasn't designed for heavy consuming Web applications, I believe there are a lot of room for improvements in this direction. The way might be redesigning jsf components rendering kits more focused on html 5, css3, js new best practices.
Client side framework will end next year with web components and http/2. Today they are good, if you need fast development and don't care much about client performance. And yes badly written graph paper code has more impact on speed, than use of more complex js library.
Jsp are great if you need better control of generated HTML quality. Also you don't have to use expression language, which is horrible slow. (using scriptlets for passing graph paper values to jsp tags, no other code) Also jsp tags can be translate with tag plugins, which will get your server to light speed. (for example ebay use tagplugins)
Maybe I have a bias because i have a large app on JSF2+Richfaces4, and whether it have clear benefits in comparison of the way we used to develop GUI interfaces some years ago (Struts1.2 or only servlets+jsp). But also, i've found a lot of problems related graph paper to the way that JSF works (and many workarounds too). So some years ago, I've started two projects with Backbone and Rest and this architecture was so useful, so my bias.
@Simon: JSF 2.2 does a pretty good job of supporting HTML5 but the standard components are pretty primitive so that isn't really a problem. The plethora of JSF Component libraries out there make up for this and the responsibility for HTML5 support lies with them and not JSF. JSF2.2 graph paper and PrimeFaces is probab
No comments:
Post a Comment