Showing posts with label jsf. Show all posts
Showing posts with label jsf. Show all posts

Tuesday, September 14, 2010

Using hibernate generated collection in h:dataTable

It's a bit difficult to pick the correct title for the thing that I'm going to write :) It's about having your POJO generated by hibernate and then feed it to h:dataTable.

When your object has a collection properties and the elements contained are unique within the collection, hibernate will create a Set to contains it. The thing with a Set is h:dataTable just can't accept it. The simplest solution is to change Set to Collection object and h:dataTable can accept it and Hibernate won't complain about it :)

Tuesday, February 26, 2008

JSF strange behaviors

Two strange behavior of JSF (at least this is what I remembered)
1. Your backing bean only specify getter method (in my case, it returns a collection) and you're using it in h:dataTable. Submitting the form (invoking any action on the page) does nothing, no exception, no sign of anything happening... not a single clue. After one hour wasted, I found out that creating a setter method solves it. It seems that JSF try to call the setter and then fails ungracefully.

2. I have a selectOneMenu and I use a getter method for the selectItems, the List of SelectItem are created whenever the getter is invoked (I know it's not good, just hear the story :). Accessing the page yields exception complaining that there is no selectItem provided (null). Strange thing is the getter method is invoked not in render phase, why? Long story short, I add a property in the backing bean holding the List of selectItem and the getter method is still the same getter method as previously, only at this time I initialize the collection once (better pattern, rite? ;). It works! No more error.


These two strange behaviors that I remembered, are they somehow in the JSF specification?
... I guess I have to try to find out myself.

Tuesday, October 23, 2007

Date is displayed wrong-decrease 1 day(JSF)

Have you ever get confused because your Date is displayed wrong (i.e. decreased 1 day) when you use h:outputText?
This might happen because JSF spec says that date converter defaults to using standard UTC timezone and you're happen to live in some other timezone, in my case it is GMT+07.

My first idea was to build a date converter which use the default timezone in the server and use f:converter to specify my converter id. Somehow the date pattern can't be passed to my converter, that's sad, I don't want to force a certain pattern.

My second idea is simply to create a method in my utility bean called
public String getTimeZone() which will return the default timezone ID, and use it to specify the timezone attribute in f:convertDateTime facet.

so the outcome looks like this :
<h:outputText value="#{track.movedDate}">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" timeZone="#{constants.timeZone}"/>
</h:outputText>

All that needs to be done is to put the convertDateTime facet in every outputText.