This example was greatly inspired by the Stripes and jQuery AJAX Forms article from Freddy Daoud, but with some nice improvements
Last week I was working on a new Stripes/AJAX example. It involves having a table listing entities, being the last row of the table a form for adding new ones.
The form gets submitted via AJAX, using jQuery, and the response is validated in order to check if the HTTP session is still valid.
If everything is OK, the list is refreshed and a success message appears. On the other hand, if validation errors occur, the list is refreshed and an error message appears.
Also, if the user’s session has expired on the server, an alert is shown to inform the user that his session is invalid, and the page is reloaded so the user can login once more.
Read the rest of this entry »
A long time has passed since my previous BIRT examples Deploying BIRT Report Engine API with Jakarta Struts
and Deploying BIRT Report Engine API with Stripes
.
Although they have received a lot of attention and downloads, the examples were really basic and are now outdated.
Since I had to use BIRT in my last projects I decided to update my BIRT/Stripes example.
This example doesn’t depend on the Tribix project anymore since BIRT supports HTML/Paginated HTML, PDF, Excel, Word, PowerPoint, and PostScript outputs (images/charts are not embedded in Excel output).

I’ve tried to follow some good practices
that I think are important to use in a production application:
- There is a significant cost associated with creating an engine instance, due primarily to the cost of loading extensions. Therefore, each application should create just one ReportEngine instance and use it to run multiple reports. In this example the engine is started in the context listener and the same instance is always used.
- All texts in the report should be loaded from the resources so the application can be fully localizable and fully internationalized.
- You should use a JDBC data set to preview your report with BIRT designer but you must swap the data set in runtime to use data from your business logic.
- You should use predefined styles instead of custom styles as much as you can.
- Not a good practice but often a requirement, hide the master page when generating a HTML report, and change the visibility of elements so they are visible only to specified outputs.
For this example BIRT Runtime Engine 2.2.2 2.3.1, and Stripes Framework 1.5 were used.
Read the rest of this entry »
Last week I changed my hosting provider from Site5 to NearlyFreeSpeech.NET.
Despite the fact that the first one is faster than the second, NFSN is a lot more cheaper (I only pay what I really use).
So in order to speed up my site and save bandwidth (the more I use the more I pay) I use .htaccess file to gzip my text based files and optimize cache HTTP headers.
Although this site is powered by Wordpress which has some really great plugins to optimize PHP output I wanted a more generic solution which can be applied to all PHP web applications.
I also try to follow as much as I can the rules for high performance web sites so don’t be surprised if some Expires header seems too long (far future Expires header rule requires at least 172801 seconds).
Read the rest of this entry »
I’ve got a lot of feedback after my article Exactly what is Alfresco?. The questions I’ve received often was where to find more info about WCM with Alfresco.
You can Download Alfresco Web Content Management 2.1 under Download Alfresco Community Network. There you can find Alfresco 2.1 Web Content Management Product Evaluation Guide which is a very complete guide about the WCM module.
Hope this helps.
Microsoft has created Code Gallery.
Code Gallery is a place for projects sharing, created to demonstrate .NET key features with a primary focus on C#.
Inspired by the Spring with Stripes integration I made a new one named EJB3 with Stripes.
This extension allows you to inject your EJB beans into your Action beans.
Please fell free to use it, and to visit the Stripes and EJB3 project at Google Code.
In my current web project I was having some performance issues, I needed a tool that allowed me to do some testing so I can see what’s wrong and what I can do better so my application perform faster.
My search lead me to High Performance Web Sites and YSlow, a very good talk by Steve Souders the Chief Performance Yahoo! at Yahoo!
YSlow is an easy-for-use plugin that allows you to inspect any web page just clicking a button.
YSlow analyzes web pages and tells you why they’re slow based on the rules for high performance web sites. YSlow is a Firefox add-on integrated with the popular Firebug web development tool. YSlow gives you:
- Performance report card
- HTTP/HTML summary
- List of components in the page
- Tools including JSLint
A good way to reduce the number of Http Connections required to load a web page is to store images and other resources in the browser cache.
Expires is a HTTP header that allows you to define when a resource (image, css, javascript, …) will need to be reloaded. It is a String representation of a Date in the format EEE, dd MMM yyyy HH:mm:ss z.
Cache-Control response headers give Web publishers more control over their content and address the limitations of Expires.
To correctly produce these headers I implemented a Java cache filter.
Using the cache filter is very simple. Grab it here and configure your web.xml, here’s an example:
<filter>
<filter-name>imagesCache</filter-name>
<filter-class>com.samaxes.cachefilter.presentation.CacheFilter</filter-class>
<init-param>
<param-name>privacy</param-name>
<param-value>public</param-value>
</init-param>
<init-param>
<param-name>expirationTime</param-name>
<param-value>2592000</param-value><!-- 30 days -->
</init-param>
</filter>
<filter>
<filter-name>cssCache</filter-name>
<filter-class>com.samaxes.cachefilter.presentation.CacheFilter</filter-class>
<init-param>
<param-name>privacy</param-name>
<param-value>public</param-value>
</init-param>
<init-param>
<param-name>expirationTime</param-name>
<param-value>604800</param-value><!-- 7 days -->
</init-param>
</filter>
<filter>
<filter-name>javascriptCache</filter-name>
<filter-class>com.samaxes.cachefilter.presentation.CacheFilter</filter-class>
<init-param>
<param-name>privacy</param-name>
<param-value>private</param-value>
</init-param>
<init-param>
<param-name>expirationTime</param-name>
<param-value>172801</param-value><!-- 48 hours + 1 second -->
</init-param>
</filter>
<filter-mapping>
<filter-name>imagesCache</filter-name>
<url-pattern>*.png</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>imagesCache</filter-name>
<url-pattern>*.jpg</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>imagesCache</filter-name>
<url-pattern>*.gif</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>cssCache</filter-name>
<url-pattern>*.css</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>javascriptCache</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping> |
Note: YSlow far future Expires header magical number is 172801 seconds (48 hours + 1 second).
After googling a bit for error “java.lang.OutOfMemoryError: PermGen space” I found many sites talking about that problem. Some tried passing command line arguments to the JVM or changing the size of the PermGen space, others end up recommending using a VM from BEA or IBM, all without success.
But after a closer look at their comments I ended up at Frank Kieviet blog.
Frank explains what really is a PermGen error
The problem in a nutshell
Application servers such as Glassfish allow you to write an application (.ear, .war, etc) and deploy this application with other applications on this application server. Should you feel the need to make a change to your application, you can simply make the change in your source code, compile the source, and redeploy the application without affecting the other still running applications in the application server: you don’t need to restart the application server. This mechanism works fine on Glassfish and other application servers (e.g. Java CAPS Integration Server).
The way that this works is that each application is loaded using its own Classloader. Simply put, a Classloader is a special class that loads .class files from jar files. When you undeploy the application, the Classloader is discarded and it and all the classes that it loaded, should be garbage collected sooner or later.
Somehow, something may hold on to the Classloader however, and prevent it from being garbage collected. And that’s what’s causing the java.lang.OutOfMemoryError: PermGen space exception.
PermGen space
What is PermGen space anyways? The memory in the Virtual Machine is divided into a number of regions. One of these regions is PermGen. It’s an area of memory that is used to (among other things) load class files. The size of this memory region is fixed, i.e. it does not change when the VM is running. You can specify the size of this region with a commandline switch: -XX:MaxPermSize. The default is 64 Mb on the Sun VMs.
If there’s a problem with garbage collecting classes and if you keep loading new classes, the VM will run out of space in that memory region, even if there’s plenty of memory available on the heap. Setting the -Xmx parameter will not help: this parameter only specifies the size of the total heap and does not affect the size of the PermGen region.
… and how to use new profiling tools in Java 6 to fix Classloader leaks.
Resuming, the steps are:
- start your application server
- deploy and run your application
- undeploy the application that is leaking (just the application not the server)
- trigger a memory dump
jmap -dump:format=b,file=leak <PID>
- run jhat (with modification, Java SE SDK 6.0 update 1 has the updated code)
jhat -J-Xmx512m leak
- go to jhat report http://localhost:7000/ (http://localhost:7000/oql/ if you need the OQL (Object Query Language))
- find a leaked class (any class of your application since you shouldn’t see any objects of the classes that you deployed)
- locate the Classloader
- find the “Reference chains from root set”
- inspect the chains, locate the accidental reference, and fix the code
Some try even to go further on finding Orphaned Classloaders others try to nicely present the leaking classes in a form of a HTML table histogram.
These tools can really help, use them!
Resources
Coding conventions are rules that computer programmers follow to ensure that their source code is easy to read and maintain.
Why is that important?
Sun Microsystems provides the following rationale for the Java Programming Language:
Code conventions are important to programmers for a number of reasons:
- 80% of the lifetime cost of a piece of software goes to maintenance.
- Hardly any software is maintained for its whole life by the original author.
- Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly.
- If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create.
Crossbow Software has gather a set of code conventions and programming style documents, take a look at their Coding Style Standards download page.
Approximately 2 years ago I’ve written a set of PHP Tutorials that served as a guideline for a Beginner’s PHP Training Course. These tutorials were made with the WAMP solution stack in mind.
Since I’ve been working with Java EE Technologies and Servers recently, I’ve decided do add another one explaining how to install JBoss Web 1.0.1 GA with PHP support (PHP Handler Servlet).
This was based on a tutorial by Philippe Fievet that is now offline for some reason.