Insights into Java Server Faces


Howto use PreRenderViewEvent on a component or any managed bean

Filed under: JSF — Hanspeter @ 23:15

JSF 2.0 introduced many events, one of it is javax.faces.event.PreRenderViewEvent. But there is a pitfall – listeners for this event are registered in application scope. Therfore one must be very carefull to not subscribe any UIComponent or managed bean as listener for PreRenderViewEvent. However, sometimes it’s required to do something during PreRenderViewEvent processing on a UIComponent – for example modify the completely built component tree e.g. using some rules.




Suppress second execution of buildView() as performane improvement when using Facelets views

Filed under: JSF — Hanspeter @ 21:58

Since JSF 2.0 when using Facelets view definitions the component tree is built twice on postback requests, once in RESTORE_VIEW phase and once in RENDER_RESPONSE phase. The rebuild in the render phase is necessary in case the page author used conditional includes. On big views several hundred component build the component tree – this may take some 100ms per buildView() execution – saving that once will improve the performance. (more…)


Reduced session size with empty Maps/Lists taking zero bytes space allocation

Filed under: Java, JSF — Hanspeter @ 23:03

It’s quite a while since my last post and this one is related to JSF but not only, it might also be usefull for other use cases. I will show a way to not allocate any space for empty collections (mainly Lists/Maps) unless a first entry is added – and that in a way that is fully transparent for the using part of the Map/List. This helps to keep managed beans containing data as small as possible and therefore allows to reduce session size. (more…)


Wrapping PartialViewContext – or howto automatically add clientIds to render on AJAX requests

Filed under: JSF — Hanspeter @ 19:39

Imagine a JSF 2.0 based input view working with AJAX and you have h:messages positioned above of this input form – and you want the messages area to be rerendered on each validation step. You now will have to add the clientId of h:messages to all f:ajax render=”..” behavior definitions – or somehow add the clientId of h:messages automatically to the list of components to be rendered on partial requests. This article will show how to implement the automatic adding of a clientId to the list of components to render on partial view requests. (more…)


Pass component references using simple bindings management

Filed under: JSF — Hanspeter @ 22:02

Sometimes binding of UIComponent comes in very handy. For example if you want to pass client ids into a composite component to alow the cc to use these ids with attributes. It would be very boring to specify the full client ids explicitly. This article will show how component references can be passed on in a simple generic way.


Using File Upload in JSF Portlets with Weblogic Portal

Filed under: JSF, Portal — Hanspeter @ 13:59

According to this Oracle whitepaper it is not possible to use Tomahawk File Upload within a JSF Portlet – they recommend to use a non JSF Portlet for that. Well, we found a solution to get File Upload working within JSF Portlets. (more…)


Combine multiple properties files into one ResourceBundle

Filed under: Java, JSF — Hanspeter @ 20:54

Sometimes it would be nice to combine multiple properties files into one single ResourceBundle. For example, a part of the resources is provided by some library and another part of the resources should be provided by the application using that library.



MultiValidator component allows validation across multiple input fields

Filed under: JSF — Tags: , — Hanspeter @ 22:52

JSF provides validation, you can even attach multiple validators to a single input component. But it does not (yet?) support validation across multiple input components. To address this shortcoming we developed a MultiValidator component.  (more…)


Reduce server side state size with JSF 1.2 and Facelets by 30-60%

Filed under: JSF — Tags: , — Hanspeter @ 13:21

Beside his appointments at Jazoon 2009 we had the opportunity to have Ed Burns at our office in Credit Suisse (CS) to work on some suggenstions regarding JSF improvements. After a short discussion it was agreed that there is only one point to look at on the currently used JSF 1.2 and Facelets – the other improvements will most likely be covered by JSF 2.0 or would have to be looked into later. (more…)


using a custom Lifecycle implementation to handle Exceptions in JSF 1.2

Filed under: JSF — Tags: — Hanspeter @ 22:48

Real application need to handle unexpected Exceptions in a save way by e.g. render an error page and behave according to the type of exception (some exceptions might allow to show a message and continue with the application, other might need to terminate the session). JSF 2.0 will provide exception handling support, but you can also handle exceptions before JSF 2.0 using a custom lifecycle as shown below.


Older Posts »

Create a free website or blog at