Archive for June, 2010

How to configure JSF to get the browser Back button working

Lately, I had a problem with one of my JSF applications which is using RichFaces.
The problem was happening when the user was hitting the browser Back button. Well, you would say that it is a usual problem in web development. But still, because we cannot disable the browser Back button, the web application needs to work fine if the user decides to click on it!

Anyway, let’s get back on topic. As I said, the problem occurred if the user was clicking on the Back button but the funniest thing is it was happening when he was clicking twice on it! Why did it work fine when clicking once but not twice? 😮

The solution is quite simple actually.
It was coming from one of the options in MyFaces configuration: com.sun.faces.numberOfViewsInSession.
Here is a quick explanation of this option:

com.sun.faces.numberOfViewsInSession
Specifies the number of views that are stored in the session when Server-Side State Saving is used. If set to true while client-side state saving is being used, reduces the number of bytes sent to the client by compressing the state before it is encoded and written as a hidden field. The default for this parameter is 15.

So basically, JSF is storing each page previously viewed by the user in session. And, as you can see from the description above, JSF will stored a maximum of 15 pages by default. However, it was set to 1 in my application, which means only ONE page would be stored…
This was obviously the reason why the application was working fine if the user was clicking only once on the Back button but not twice! 😀

For the same reason, you should also check the option org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION which is default to 20:

org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
Defines the number of the latest views that are stored in session. This option is only applicable if the state saving method is set to server. The default for this parameter is 20.

For more information about JSF options, please have a look at the following page:
http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rweb_jsfengine.html

, , , ,

No Comments

Image manipulation in VBScript

I am back on Windows development. It is not what I prefer but still, it is development so I am right here! 😉

My task was to upload an image from a website (nothing difficult there) but the application has to resize and crop the uploaded image before saving it on the hard drive in order to save space.
Oh, and I forgot to mention that the website is built in VBScript (it would have been too easy if it has been built in ASP.Net…). 🙄

I went across a lot of image management libraries which work with VBScript during my search:

But I must admit that the most difficult part of this task was to find a good and FREE library.
The one I finally picked is ImageMagick.

Once the library is installed (click here to go to the download page), you can use the following code to resize the image to a maximum of 800 pixels and crop the white space around it:

Dim imageMagick
Set imageMagick = CreateObject("ImageMagickObject.MagickImage.1")

imageMagick.Convert "C:/testimage.jpg", "-fuzz", "10%", "-trim", "-resize", "800x800>", "C:/thumb-testimage.jpg"

Obviously, this tool can do much more than that, but this will be subject of another topic.
Or you can simply read the documentation: http://www.imagemagick.org/Usage/

, ,

1 Comment