26 March 2007 - 20:06Some JSF short-comings

I really needed one thing today: inheritance between managed beans. Well, I didn’t find out how to implement it. I basically needed one managed bean (let’s say PersonList which has a List persons) to share its persons with another managed bean MortgagePersonList which subclasses PersonList and uses the persons List put together by PersonList during processing.

Java code:
public class PersonList{

protected List persons;
// some methods for manipulating persons (sounds pretty Orwellian, I know ;-))
}
public class MortgagePersonList extends PersonList{

// re-submits their mortgages application
public String resubmitMortages();

}

JSF code:

<!– set-up the PersonList managed bean –>

<managed-bean>

<managed-bean-name>personList</managed-bean-name>

<managed-bean-class>com.PersonList</managed-bean-class>

<managed-bean-scope>session</managed-bean-scope>

</managed-bean>

<!– set-up the MortgagePersonList managed bean –>

<managed-bean>

<managed-bean-name>mortgagePersonList</managed-bean-name>

<managed-bean-class>com.MortgagePersonList</managed-bean-class>

<managed-bean-scope>session</managed-bean-scope>

</managed-bean>
I was expecting that I could inherit one managed bean from another so that I could re-use the persons List transparently. No such luck. So I was left with saving the persons List in the Session in the PersonList bean and retrieving it from the Session in the MortgagePersonList object. I thought that I could use an environment-independent Session object, the only one that I could retrieve via FacesContext.getCurrentInstance().getExternalContext().getSession(false) was actually an Object which has to be cast down to HttpSession. It is pretty weird that the ExternalContext is modeled similarly to HttpServletRequest (just look at getRequestParameterMap, getRequestParameterNames, getRequestPathInfo, getRequestServletPath), it speaks a bit about JSF’s environment independence. It would be interesting to know the reasons behind not developing environment independent sessions (getSession should return an interface specifying the contract for a session and not an Object which can be cast down to a specific implementation like HttpSession), this could help when implementing dialogs.
One other thing that I hate about JSF is the amount of informal specifications, you know the fact that if your managed bean controller is returning a String than you should map that String to a navigation case and so on. It is pathetic, it would have been much better if this functionality would have been specified in a more rigorous way like defining it in an interface. But it looks like Sun didn’t feel quite up to the task of spec-ing out the user interaction (this is what JSP should be all about).
I really like the abstraction layer they created but it looks like it was fully finished. My 2 cents.

No Comments | Tags: Development

Add a Comment