May 4, 2008

Dynamic tables with JMesa


JMesa is a very useful open source project.It is a dynamic HTML table that allows you to edit, filter, sort, paginate and export your data. By my opinion it is a really cool and useful tool for development a java web applications. Here is a simple and fast tutorial and example.
What do you need to run this tutorial?
1. JDK, JMesa requires 1.5 or above, I recommend 1.6
2. IDE - I'll use my favorite eclipse
3. JMesa latest
4. JQuery, JMesa requirement, prefer the latest version
5. I'll use Struts

OK, now what to do. Extract the jmesa archive and create new web project. Put jmesa.jar on your WEB-INF/lib directory. Put the JavaScript, CSS and image files in the corresponding folders. For me that would be /scripts, /styles and /images. For the data bean I'll use simple class Framework

public class Framework {
String name;
String url;
String license;
Boolean like;

public Framework(String name, String url, String license, Boolean like) {
this.name = name;
this.url = url;
this.license = license;
this.like = like;
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
public void setName(String name) {
this.name = name;
}
public void setUrl(String url) {
this.url = url;
}
public String getLicense() {
return license;
}
public Boolean getLike() {
return like;
}
public void setLicense(String license) {
this.license = license;
}
public void setLike(Boolean like) {
this.like = like;
}
}

Our framework action or servlet must set the data collection, in our case it will do something like this:

Framework jquery = new Framework("jQuery", "http://jquery.com", "MIT & GPL", true);
Framework mootools = new Framework("Mootools", "http://mootools.net/", "MIT License", true);
Framework gwt = new Framework("Google Web Toolkit", "http://code.google.com/webtoolkit/", "Apache License", false);
Framework dojo = new Framework("Dojo", "http://dojotoolkit.org/", "BSD & AFL", false);
Framework prototype = new Framework("Prototype", "http://www.prototypejs.org/", "MIT License", false);

ArrayList frameworks = new ArrayList();
frameworks.add(jquery);
frameworks.add(mootools);
frameworks.add(gwt);
frameworks.add(dojo);
frameworks.add(prototype);

request.setAttribute("frameworks", frameworks);


And our framework.jsp file:

And thats it. Our jmesa table is ready to be shown on public. Simple, easy and fun.

5 comments:

Radhika Ganesan said...

Hi,
I am trying to use JMesa as i need to make a POC for the same, if it comes out to be simple...may be we can use it in future projects. But the issue is that i am not getting good help from anywhere...i am reading the documentation. Some more information can be very useful.
Please take out some time to explain more. Are you using JMesa as well for some application ?

ldeveloper.blogspot.com said...

Yep, I use JMesa in some projects. I'll try to write some more when I have enough time.

Anonymous said...

boss why r u fooling people wher is ur jmesa code.

geetha said...

Hi,

Is there any option to change the filter cell?? Since the filter cell looks like textbox, filter option is not obvious to the user.. Can anybody help me If its possible to change it.

Anonymous said...

Excuse me, can you say more about this row?
(request.setAttribute("frameworks", frameworks);)
Where you defined request object.

Popular Posts