Current Challenge Update

Last week I blogged about an issue that I was focusing on in the current project that I am working on. In my hunt for a solution, I came across a couple of MyFaces tags that I didn’t pay much attention to and it turns out that they were the solutions that I was looking for. First up the default implementation of the dataTable component is not robust enough; yes, it does all the fancy things of iterating through a list of objects but when additional capabilities are required, it fell short (miserably so). I found myself remembering my time with ASP.NET 2.0 with a heavy dose of nostalgia. ASP.NET 2.0 allows a developer to create seemingly advanced UI scenarios without much complications of how the whole setup comes together. The GridView control is particularly intriguing.

Back to the subject: JSF RI implementation of dataTable was woefully inadequate so I looked to MyFaces’ implementation of the same control and it has this really useful attribute called “preserveModel”; when this attribute is set to true, it preserves the list that is bound to the dataTable control. I have not yet pushed this to its limit but I can see its potential already and thus I will be looking forward to creating some interesting UI scenarios.

For those interested in itemized list of accessing components in a table, here it is:

  • The simplest way to preserve the state of a dataTable is to use MyFaces’ extended implementation of the component; in particular set the preserveModel attribute to true. This is not the only attribute that is useful there are a number of other attributes that can be leveraged in the interaction between the presentation layer and the managed beans.
  • Using managed beans with request scope is generally a nasty business; too many parameters passing between the presentation layer and the managed beans. A more amenable scope would be the session scope but there is a need to ensure that the scope is not abused unless you don’t mind your code chewing up a large chunk of memory just to run. In the current project, I have a number of managed beans that need to be in the application scope since most of the data and methods they provide access to do not change regularly.

In solving this particular challenge, I have also come to discover the importance of using events in a JSF application more often as opposed passing parameters through a HTTP request query string which quickly becomes unmanageable in a sufficiently complex scenario. Events enable a more intuitive development experience and the resultant UI is quite simple and in most cases not confusing to the user (or at least that is the hope from a developer’s perspective). I am a believer in the value of an application that can communicate its state to the end user.

The main tag that led to the realization of simplicity is MyFaces’ updateActionListener tag which I am currently using to change the state of managed beans. The tag is nested inside a commandLink component and then when that commandLink is clicked on the specific details of the updateActionListener tag are also executed. Here is a code sample

<h:commandLink id=”cmdDemoCommand” actionListener=”#{demoBean.doDemoAction}”>

<h:outputText value=”Test Demo”/>

<t:updateActionListener property=”#{demoBean.currentObject.id}” value=”#{demoManager.currentId}”/>

</h:commandLink>

Without the use of the updateActionListener tag, the manner in which these properties are kept in sync would have been a complex and messy process. My current experience leads me to the conclusion that it makes it much easier to develop the back end code that manage the user’s data and particular navigation scenarios which cannot be adequately accounted for by the usual JSF navigation rules.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: