Hacking on GraphHopper - a Java road routing engine. Peter has posted 62 posts at DZone. You can read more from them at their website. View Full User Profile

Java Web Frameworks Survey

04.13.2008
| 22587 views |
  • submit to reddit

Recently I began to play with Eclipse and several web frameworks as I will be using Eclipse at work and programming with JSP. Another reason for this web-framework-survey is that I need a web front-end for my open source project Jetwick.

I love Swing so I looked at how easy it is to program something useful with up-to-date web frameworks in comparison to Swing. For NetBeans support of several web frameworks such as GWT and Wicket take a look here.

I implemented a very minimalistic example in all frameworks, but it includes three basic components. The example offers a ‘Button’ to perform some gnuplot statements, which will be grabbed from a ‘TextArea’. On the server the statements will be performed (through gnuplot) and the user gets back the calculated image. E.g. if you type ‘plot sin(x)’ and click the button you will get the appropriated graph as an image within the web page.

I used the following statements for gnuplot and you can increase the isosamples to 100 to see what will happen if the respond of the server takes too long:

set xrange[-3:7]
set yrange[1:5]
set isosamples 50
set hidden3d
splot exp(-0.2*x)*cos(x*y)*sin(y)
Just copy and paste this into the appropriate ‘TextArea’ of the application.

I chose GnuPlot for the following reasons:

  • it is free and available under linux and windows.
  • it looks nice
  • integration into LaTeX is best (good for scientists)

I used my simple class (see WebGnuplot package) to get the image from gnuplot, although there is a nice JNIBinding for gnuplot available at sourceforge.

Web Frameworks

I only chose the ‘most interesting’ open source frameworks, with the decision on whether a frameworks was interesting or not was random. I excluded frameworks where I need to program directly with Javascript. If you know other projects, where I can program in pure Java, then please let me know! Or ask me if you have suggestions or questions about the implementations.

Here is the list of the frameworks used in the survey, and how to access the examples

Click on the links to go directly to the web page of the product. I will add some more frameworks in a later post such as struts, stripes, jsf and jzeno. Please make some suggestions here.

For some more Java web frameworks look on my own list, on java-source.net or on therightsoft.com. Or take a look at this nice comparison. Through this web framework comparison I have the feeling that there are some categories of frameworks:

  • Swing like approach: Echo, Thinwire and WingS
  • ‘Integrate components’ into HTML: Wicket and Click
  • ‘integrate scripts’ into HTML: JSP, ZK (maybe better: ‘action based’?)
  • compile Java to Javascript: GWT

Please help me here to use existent categories.

4
Your rating: None Average: 4 (3 votes)
Published at DZone with permission of its author, Peter Karussell.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Bob Schellink replied on Sun, 2008/04/13 - 6:35am

Hi Peter,

Nice work comparing all the different frameworks. I always thought it would be too much work to compare them but you obviously proved me wrong there ;-)

If you have time it would be great to see a follow up post comparing the other frameworks you mentioned: struts, stripes, jsf and jzeno.

I notice for Click you used a seperate servlet to stream the image. It is actually possible to write to the HttpServletResponse directly from your Page, in this case ClickApplication. If the method Page#getPath returns null, Click won't render the page template.

So by adding the method ClickApplication#getPath to return null one can change the ClickApplication#onClicked method to stream the image directly to the HttpServletResponse#outputStream.

One last comment about your click.xml file. You don't need to explicitly map the template to the java class, Click will map them automatically.

Again great work on this.

kind regards

bob

Peter Karussell replied on Sun, 2008/04/13 - 7:47am

Hi Bob!

[quote]I always thought it would be too much work to compare them but you obviously proved me wrong there ;-)[/quote]

Hmmh, but maybe I proved that it was too much work (for a newbie) as it should be ;-)

Hopefully I will have some time to include the other frameworks.

[quote]I notice for Click you used a seperate servlet to stream the image. It is actually possible to write to the HttpServletResponse directly from your Page, in this case ClickApplication. If the method Page#getPath returns null, Click won't render the page template.

So by adding the method ClickApplication#getPath to return null one can change the ClickApplication#onClicked method to stream the image directly to the HttpServletResponse#outputStream.[/quote]

Yes I used a separate servlet and it would be better if i can avoid this. But actually I don't understand how? You mean that ClickApplication.getPath should return null if the page requests the image? Please, could you provide an example for this? Especially for the file ClickApplication.htm.

[quote]One last comment about your click.xml file. You don't need to explicitly map the template to the java class, Click will map them automatically.[/quote]

You mean I could remove the file?

Thanks for your input Bob!

Peter.

Pether Sorling replied on Sun, 2008/04/13 - 9:18am

Nice too see somebody make an effort to try out different frameworks..

Thinwire development team is pretty active they just haven't made any release for a while.

Subversion stats : http://sourceforge.net/project/stats/detail.php?group_id=170706&ugn=thinwire&type=svn&mode=12months

 

More info about the current state of thinwire. 

http://truecode.blogspot.com/2008/04/state-of-thinwire-framework-2008.html

Pether

Bob Schellink replied on Sun, 2008/04/13 - 10:39am in response to: Peter Karussell

[quote=peathal]

Yes I used a separate servlet and it would be better if i can avoid this. But actually I don't understand how? You mean that ClickApplication.getPath should return null if the page requests the image? Please, could you provide an example for this? Especially for the file ClickApplication.htm.[/quote]

Here is an example of how to stream directly: http://www.avoka.com/click-examples/direct-page.htm

However having a closer look at your example you actually want to render a html image tag. I will email you an example of this since it is probably impolike of me to flood the comments with Click code ;-)

[quote]You mean I could remove the file?[/quote]

No the file is still needed, but only the package has to be specified. From that Click will be able to map templates to classes. So you only need:

<click-app>
<pages package="de.wg.web.click"></pages>
</click-app>

kind regards

bob

Daniel Ray replied on Sun, 2008/04/13 - 12:10pm

Wow. What about JSF using MyFaces, RichFaces, IceFaces, or Facelets? Struts? Spring UI? To each his own I suppose.

Peter Karussell replied on Sun, 2008/04/13 - 3:09pm in response to: Pether Sorling

Ups, sorry for this. I will remove the comment in the article now. I thought I looked on the code stats, but really: thinwire is active!

 

Peter.

Peter Karussell replied on Sun, 2008/04/13 - 3:44pm in response to: Daniel Ray

In my planned continuation of this survey I will only cover the usage of MyFaces and Struts, because of my limited time.

Maybe you can do the necessary implementation of the others? :-)

[quote] To each his own I suppose. [/quote]

What do you mean with 'own'? Own implementation? 

Peter.

Bruno Vernay replied on Mon, 2008/04/14 - 3:28am

Interesting, I did my own little research exercise on the subject, it is a never ending work :

http://docs.google.com/Doc?id=ajgdx7ccvkxg_50ccp25f

There should really be a wiki somewhere or some kind of taxonomy to help categorizing / choosing them.

Hope it helps

Jose Maria Arranz replied on Mon, 2008/04/14 - 7:13am

My contribution: Gnuplot Web based on ItsNat

ItsNat is a new Java web application framework strongly focused on AJAX from scratch. Basically the server keeps a W3C DOM tree of the page, the client is updated automatically when the server DOM tree is changed using W3C DOM APIs, in summary: DHTML on the server. Templates are pure HTML files with no logic. ItsNat provides optional components reusing data y selection models from Swing.

This Gnuplot web version is an AJAX application.

I've spent 2 hours and 15 minutes, 50 minutes spent building the application. The remaining time was spent trying to figure how to run Gnuplot: trying to execute the pure windows version of gnuplot (failed, is a GUI), then trying the cygwin version (missing DLL cyggd-2.dll), investigating what cygwin package installs cyggd-2.dll, then installing libgd2 in my cygwin instalation and copying required dlls to setup an standalone version of Gnuplot...

This application runs on:

Desktop browsers: FireFox 1.x, MSIE 6+, Safari 3+, Opera 9+

Mobile browsers (yes including AJAX): Opera Mini 4, Opera Mobile 8.6, Minimo 0.2, NetFront 3.5 and ... IE Mobile 6 (WM6) !!

Notes: ItsNat distribution included is a prerelease of the upcoming v0.3 (current public version is 0.2)

GnuplotHelper class is slightly modified.

Source code summary:

Template:

<!-- <?xml version="1.0" encoding="UTF-8"?> -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>WebGnuplot</title>
</head>
<body>
<h2>WebGnuplot</h2>

<textarea cols="25" rows="10" id="commandsId">
</textarea>
<br />
<input id="plotId" type="button" value="Click me, to run the statements above" />
<br /><br />
<img src="" id="plotImageId" />
</body>
</html>

Template processor:

package webgnuplot;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.swing.text.BadLocationException;
import org.itsnat.comp.ItsNatComponentManager;
import org.itsnat.comp.html.ItsNatHTMLInputButtonNormal;
import org.itsnat.comp.html.ItsNatHTMLTextArea;
import org.itsnat.core.html.ItsNatHTMLDocument;
import org.w3c.dom.Element;
import org.w3c.dom.html.HTMLDocument;
import org.w3c.dom.html.HTMLImageElement;


public class GnuPlotListener implements ActionListener
{
protected ItsNatHTMLDocument itsNatDoc;
protected ItsNatHTMLTextArea textArea;
protected ItsNatHTMLInputButtonNormal button;

/** Creates a new instance of GnuPlotListener */
public GnuPlotListener(ItsNatHTMLDocument itsNatDoc)
{
this.itsNatDoc = itsNatDoc;
ItsNatComponentManager compMgr = itsNatDoc.getItsNatComponentManager();

HTMLDocument doc = itsNatDoc.getHTMLDocument();

Element commandsElem = doc.getElementById("commandsId");
this.textArea = (ItsNatHTMLTextArea)compMgr.createItsNatComponent(commandsElem);

javax.swing.text.Document swingDoc = textArea.getDocument();
String commands = "";
commands += "set xrange[-3:7] \n";
commands += "set yrange[1:5] \n";
commands += "set isosamples 50 \n";
commands += "set hidden3d \n";
commands += "splot exp(-0.2*x)*cos(x*y)*sin(y) \n";
try { swingDoc.insertString(0,commands,null); } catch(BadLocationException ex){ }
// Alternative: textArea.setText(commands);

Element plotElem = doc.getElementById("plotId");
this.button = (ItsNatHTMLInputButtonNormal)compMgr.createItsNatComponent(plotElem);
button.getButtonModel().addActionListener(this);

setImage(commands);
}

public void actionPerformed(ActionEvent e)
{
javax.swing.text.Document swingDoc = textArea.getDocument();
String commands = "";
try { commands = swingDoc.getText(0,swingDoc.getLength()); } catch(BadLocationException ex){ }
// Alternative: String commands = textArea.getText();
setImage(commands);
}

public void setImage(String commands)
{
HTMLImageElement img = (HTMLImageElement)itsNatDoc.getDocument().getElementById("plotImageId");
try{ commands = URLEncoder.encode(commands,"UTF-8"); } catch(UnsupportedEncodingException ex) {}
img.setSrc("imgservlet?commands=" + commands);
}
}

 

imgservlet servlet basically calls GnuplotHelper.getImageBytes(String) and outputs the image to the OutputStream of the request.

Enjoy

 

Jose Maria Arranz replied on Mon, 2008/04/14 - 8:23am in response to: Bruno Vernay

Bruno: There should really be a wiki somewhere or some kind of taxonomy to help categorizing / choosing them.

Some time ago I made a brief categorization of Java web frameworks, it may be useful to you:

Here and here

Regards

 

i honsali replied on Mon, 2008/04/14 - 10:19am

I think that the web framework should also be categorized by development context,
newbies/expert
small/large team
small/complex project
using or not graphic IDE with D&D component.....

personally I think that the best framework is the one you create yourself,

after using 2 or 3 different kind of web framework and once you get the big ideas behind it
it is easy to make one yourself based on velocityView for example

Peter Karussell replied on Tue, 2008/04/15 - 8:23am in response to: Jose Maria Arranz

Hi Jose,

thanks a lot for the example - it works ;-) Can I add this to the 2. part of my survey (under public domain with you as the author)?

Peter.

Jose Maria Arranz replied on Tue, 2008/04/15 - 9:14am in response to: Peter Karussell

Yes of course.

GnuPlot Web's source code is covered with the license WYWTDWT (=What You Want To Do With This)

Igor Vaynberg replied on Tue, 2008/04/15 - 2:35pm

A few corrections about Wicket

1) Comparing Wicket to Click is like comparing apples to oranges. While there are some minor similarities upon first glance, Wicket and Click have completely different focuses. Wicket focuses on stateful components, while Click focuses on stateless ones. In Click you can only have one stateful page instance per its class, in Wicket you can have multiple instances and multiple versions per instance to make the back button work properly. (This is what Click did last time I looked at it, it may have since changed). Advantages of stateful components is that they scale much better in complex UIs since the developer doesnt have to manage state manually, whether that be in session or urls.

2) The dependencies list for Wicket is completely off. Looks like you listed the kitchen sink there.

~/dev/src/wicket/wicket> mvn dependency:tree

[INFO] [dependency:tree]
[INFO] org.apache.wicket:wicket:jar:1.4-SNAPSHOT
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.4.2:test
[INFO] | \- log4j:log4j:jar:1.2.13:test
[INFO] +- javax.servlet:servlet-api:jar:2.3:provided
[INFO] +- org.slf4j:slf4j-api:jar:1.4.2:compile
[INFO] +- junit:junit:jar:3.8.1:provided
[INFO] +- javax.portlet:portlet-api:jar:1.0:provided
[INFO] \- org.apache.portals.bridges:portals-bridges-common:jar:1.0.3:provided

so really only org.slf4j:slf4j-api:jar:1.4.2:compile is required - that is only one jar.

of course if you runs this on wicket-examples project, which demonstrates integrations with spring/guice and a bunch of other modules, you will end up with the kitchen-sink list of dependencies you have.


Cheers

Igor Vaynberg replied on Tue, 2008/04/15 - 3:33pm

Some comments on the attached sources:

WicketApplication can be replaced with just:
public class WicketApplication extends WebApplication {

public WicketApplication() {
}

public Class getHomePage() {
return HomePage.class;
}

}

HomePage can be rewritten in a much more concise form:

public class HomePage extends WebPage {

private static final long serialVersionUID = 1L;

/** graph expression */
private String expression="plot sin(x)";

/**
* Constructor that is invoked when page is invoked without a session.
*
* @param parameters
* Page parameters
*/
public HomePage(final PageParameters parameters) {
Form form=new Form("messageInputForm");
add(new TextArea("statements", new PropertyModel(this, "expression"));
add(new Label("errorText")); // what is this for?
add(new WGImage("image"));
}

private final class WGImage extends NonCachingImage {

private static final long serialVersionUID = -2972050319844348290L;

public WGImage(String id) {
super(id);
}

@Override
protected Resource getImageResource() {
return new DynamicImageResource() {

private static final long serialVersionUID = -4215541582455792421L;

@Override
protected byte[] getImageData() {

try {
return toImageData(GnuplotHelper.getDefault().getImage(expression));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}


};
}
}
}

 

 

Peter Karussell replied on Tue, 2008/04/15 - 5:58pm in response to: Igor Vaynberg

Hi Igor,

thanks for your input.

I didn't want to compare apple with oranges but click and wicket looks quite close to each other for a newbie (to the web frameworks), sorry for this. So, you think Wicket is 'better'?

You mean that I should use NonCachingImage instead of the setHeaders stuff?

The errorText-label I needed for some debugging while I played with the code.

Peter.

Igor Vaynberg replied on Tue, 2008/04/15 - 5:49pm

Peter,

I didn't want to compare apple with oranges but click and wicket looks quite close for a newbie to the web frameworks, sorry.

Well, thats exactly the problem with these kinds of comparisons, to a newbie they might look the same.

So you think wicket is better?

You are asking a wicket committer if he thinks a framework he sinks a lot of his free time into is better then anything else out there? What do you think the answer is? :)

But, if you ask me to compare wicket to another framework I probably would not be able to come up with anything meaningful either. There are some basic design choices that differentiate all the major frameworks, some of them are: state management, markup handling, pojo model, testability, component hierarchy (static vs dynamic), community, books, etc. You can probably figure these out even if you havent used the framework extensively. Then you figure out which of these choices jive more with what you want in the framework for a particular app - and there is your choice.

Another good thing is to ask the community behind the framework for help. Give them a list of assumptions you have come up with and ask for validation.

You mean that I should use NonCachingImage instead of the setHeaders stuff?

Yep, there is no reason to reinvent the wheel by setting the headers yourself.

 

 

 

 

Marcos de Sousa replied on Wed, 2010/07/14 - 3:50am

I use ZK in production environnement since version 2.0.4. All version 2.x.x, 3.x.x, 5.x.x are less than 2.5 MB.

Where did you get 20 MB?

Peter Karussell replied on Wed, 2010/07/14 - 4:01am in response to: Marcos de Sousa

I am sure that you are right. Although I tried to reach the best for every framework. (the licensing of ZK is now also nice!)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.