|
|
||
Simon Brown's BlogNovember 2005 ArchivesComparing webapp frameworks : Model 1 with scriptletsPosted by simongbrown on November 23, 2005 at 11:42 AM | Permalink | Comments (1)Before we dive into the frameworks, I want to drop back to basics to give some context behind why the frameworks exist and what benefits they provide. For this reason, let's look at a naive model 1 implementation of the sample application. If you're already familiar with the whole model 1 vs. model 2 thing, you might want to skip reading this particular entry.
Overview
Home page
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="domain.*,
java.util.Iterator,
java.text.DateFormat" %>
<%
BlogService blogService = new BlogService();
Blog blog = blogService.getBlog();
%>
<!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">
<head>
<title><%= blog.getName() %></title>
<link rel="stylesheet" href="screen.css" type="text/css" />
</head>
<body>
<div id="container">
<h1><%= blog.getName() %></h1>
<h2><%= blog.getDescription() %></h2>
<%
Iterator it = blog.getBlogEntries().iterator();
while (it.hasNext()) {
BlogEntry blogEntry = (BlogEntry)it.next();
%>
<div class="blogEntry">
<h3><%= blogEntry.getTitle() %></h3>
<%
if (blogEntry.getExcerpt() != null) {
%>
<%= blogEntry.getExcerpt() %>
<p>
<a href="viewBlogEntry.jsp?id=<%= blogEntry.getId()%>">Read more</a>
</p>
<%
} else {
%>
<%= blogEntry.getBody() %>
<%
}
%>
<p>
<%
DateFormat dateFormat = DateFormat.getDateTimeInstance(
DateFormat.LONG, DateFormat.LONG, blog.getLocale());
dateFormat.setTimeZone(blog.getTimeZone());
%>
Posted on <%= dateFormat.format(blogEntry.getDate()) %>
</p>
</div>
<%
}
%>
</div>
</body>
</html>
I'm not going to explain each and every line, but the basic structure breaks down as follows.
For the "read more" link, this is simply implemented as a call to the blog entry detail JSP page, passing the blog entry ID as a parameter. Notice how this is conditionally included, depending on whether the excerpt is null - it's a good example of the simple presentation logic that you'll find in many web applications. The date formatting code is another example.
Blog entry detail page
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="domain.*,
java.text.DateFormat" %>
<%
BlogService blogService = new BlogService();
Blog blog = blogService.getBlog();
BlogEntry blogEntry = blog.getBlogEntry(request.getParameter("id"));
if (blogEntry == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
%>
<!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">
<head>
<title><%= blogEntry.getTitle() %> : <%= blog.getName() %></title>
<link rel="stylesheet" href="screen.css" type="text/css" />
</head>
<body>
<div id="container">
<h1><%= blog.getName() %></h1>
<h2><%= blog.getDescription() %></h2>
<div class="blogEntry">
<h3><%= blogEntry.getTitle() %></h3>
<%= blogEntry.getBody() %>
<p>
<%
DateFormat dateFormat = DateFormat.getDateTimeInstance(
DateFormat.LONG, DateFormat.LONG, blog.getLocale());
dateFormat.setTimeZone(blog.getTimeZone());
%>
Posted on <%= dateFormat.format(blogEntry.getDate()) %>
</p>
</div>
</div>
</body>
</html>
The scriptlet at the top of the page is probably the most interesting because that piece of code is responsible for locating the requested blog entry or sending the user off to an error page, which is simply configured through the <error-page> <error-code>404</error-code> <location>/404.jsp</location> </error-page>
Summary
Comparing webapp frameworks : Domain modelPosted by simongbrown on November 09, 2005 at 04:21 AM | Permalink | Comments (1)
Before we kick off our look at webapp frameworks, let's establish the domain model we're working with. It's pretty simple - blogs and blog entries, residing in a package called
Because I want to concentrate on the presentation aspects of the frameworks this time around, I'm ignoring the persistence mechanism. Instead, I'm just assuming that data access will be achieved via a "service", regardless of whether it uses direct JDBC, a DAO, a web service, Hibernate, etc. So that's the model. The question is, will any of the frameworks or view technologies require us to change it? Comparing webapp frameworks : RequirementsPosted by simongbrown on November 04, 2005 at 05:45 AM | Permalink | Comments (8)So, to compare webapp frameworks we need an example web application. I've chosen to build a simple blog. Here are the functional requirements.
And here are some non-functional requirements, just to make things a little more interesting.
Here are some screenshots to show what this all looks like.
Figure 1 : Home page.
Figure 2 : Blog entry detail page.
Figure 3 : Page not found page. As I've said before, I hoping to make this an iterative process and there's plenty of scope for adding some interactivity into the example application. Next up is a look at the domain model. Comparing webapp frameworks : Why?Posted by simongbrown on November 03, 2005 at 11:59 AM | Permalink | Comments (11)After posting Comparing webapp frameworks : Introduction yesterday, I got lots of feedback - some good, some bad. So, why am I doing this? First off, here are some of the negative comments.
Fantastic! At least people are talking and I got some response. Great to see that the community is alive. :-)
Choice
Nobody cares about the simple stuff
Consistency and reduced learning curve
The other thing to pick up on here is that some of the framework sites do have incredibly simple examples. They're even simpler than the application I've come up with and that's a problem. Once you stray outside of the simple example you have to start digging around the docs. If I can at least go slightly deeper than the very simple examples, again, I think this adds value.
The evolution of web MVC
Just to clarify, my sample application is read-only from the perspective of the user. The content is dynamic, but the user can't update it. As I said, I am hoping to make this an iterative process and revisit it to add further levels of detail. I've got to start somewhere though. ;-) Comparing webapp frameworks : IntroductionPosted by simongbrown on November 02, 2005 at 12:21 PM | Permalink | Comments (9)Struts, WebWork, Stripes, Spring MVC, Wicket, Tapestry, JSF, etc, or even rolling your own. With so many J2EE web application frameworks to choose from, how do you decide which one to use? Several articles (e.g. JavaServer Faces vs Tapestry) and presentations (e.g. Comparing Web Frameworks) already exist, but they generally concentrate on a small subset of the available frameworks. Over the next few weeks, I'm going to implement a small web application using as many J2EE web application frameworks that I can get my hands on. I'll be using the resulting code to compare and contrast what the frameworks provide and how they work. Clearly this is a massive task so, to reduce the scope, I'm going to focus on what it takes to build a read only web application. If I were to hazard a guess, I'd say that the 80-20 rule applies. 80% of a web application is read only and 20% is interactive (e.g. HTML forms, AJAX, etc). Of course, this is changing with technologies like AJAX, but we're still on the upward curve. Traditionally, that 20% is the most complex and is an area where many web application frameworks claim their unique selling points. For this reason, I may iterate over the evaluation process to take into account how the frameworks help web developers build interactive webapps. For now, I'm going to look at whether the frameworks make doing the 80% easy. In addition to looking at the webapp frameworks, I'm also going to compare and contrast some of the view technologies that are currently available. Here, I'm talking about JSP (normal and XML formats), Velocity, FreeMarker, etc. I think this adds an interesting twist and your choice of view technology may have an impact on your framework decision. Stay tuned, it should be an interesting journey! | ||
|
|