Tuesday, November 22, 2005

AJAXifying JSF (aka Making AJAX Enabled Components in MyFaces)

There has been a lot of discussion on the MyFaces developers list on how best to incorporate AJAX (Asynchronous JavaScript and XML) into JavaServer Faces (JSF) components. The first components were simple updating components that would retrieve updated information from the server and replace some elements' innerHTML. These included an InputSuggestAjax component that worked like Google Suggest and AutoUpdateDataTable that would get updated list information and update a table in place at a specified interval. Both very cool components made by Martin Marinschek. The main work on these was to encode an ajax response that was just the html required to replace the current html that was being displayed.

I needed components that could be interactive and update the backing model on the server side as well as update so there was a lot of extra work required.

On the client:

  1. Instead of submitting forms in the traditional way, everything has to be submitted through the XMLHttpRequest using javascript.
  2. Components had to be javascript ready to push their changes to the server
  3. Error handling (validation, etc) had to be done dynamically on the client side
On the server:
  1. Decode an incoming request
  2. Update backing model components
  3. Return an error response or a success response
The normal JSF lifecycle consists of the following phases:
  1. Restore view
  2. Apply request values; process events
  3. Process validations; process events
  4. Update model values; process events
  5. Invoke application; process events
  6. Render response
With a normal request you would go through this entire process on every component in the view tree. When you are just updating a single component, this lifecycle is far from optimal. In order to short circuit this lifecycle, a PhaseListener is executed before the Apply Request Values phase, performs the lifecycle on the affected component(s) only, renders a relatively tiny ajax xml response, then completes the response so nothing further is done. So the only phase that is fully executed is the Restore View phase. This should show some major performance improvements.

The Components

All of the components had to be modified to support this new scripting when decoding and when encoding (rendering). The currently available components that you can use and test are:

- inputText (with options to show buttons for submit and cancel, default is to
submit onChange)
- selectManyCheckbox
- selectOneRadio
- selectBooleanCheckbox (with options to use on/off images instead of
a checkbox)

These are available as part of the MyFaces Sandbox package. See inputAjax.jsp for examples on usage. The best thing about these components to a developer is the ease of use, for instance, using inputTextAjax is just as simple as using inputText:

<s:inputtextajax value="#{inputAjaxBean.text2}" id="text2" forceid="true" onsuccess="successful" onfailure="failure" onstart="starting" showokbutton="true" showcanceltext="true"/>

( See wiki documentation for more info on usage. )

I'd love to hear any comments or suggestions you may have.

Saturday, November 19, 2005

Is Tagging Relevant?

rel8r is an experimental project I launched on Nov. 17, 2005 at http://www.rel8r.com/ . I made it for several reasons, but one such reason was to see if tagging is actually relevant. I didn't know the answer, but I set to find out and the result is rel8r.

The most interesting thing as it turns out is that searching on tags lets you find things that you wouldn't have thought to look for. It's more of a discovery than a search. I think this is where the difference between regular search engines and searching on tags lies. With Google and other search engines you are looking for very specific things and the better the engine, the more chance you have of finding what you want. With rel8r, it's more something like "what will I find if I search for X", where X can be anything (assuming people have tagged something with X).

Lets try an example so you can see what I mean. First, lets try "golden gate bridge", on rel8r and Google. The first thing you'll probably notice is the pictures that people have tagged showing up on rel8r since those catch the eye first. It's a nice augmentation to normal search results, but when you get to reading the text entries, you'll find seemingly random things that are actually related to the Golden Gate Bridge; upcoming parties and events, things that people have bookmarked, some people offering boat trips in the San Francisco Bay, among other things. Now the Google results are more specific, the first result is http://www.goldengatebridge.org/, the next couple are more government sites that have to do with the bridge, and then some results are sites with information and tourism types of things. The Google search is obviously very relevant if you are trying to learn more about the bridge. The rel8r search is more about what's new with the bridge, what people are saying, and what people are seeing.

Now lets try a product search, how about the Xbox 360 since there is so much hype about it right now and I'll use Yahoo as the search engine this time to be fair (I really like what I'm seeing on Yahoo search these days btw, just as good as Google I dare say). My rel8r search showed many things including some pictures of the xbox like the one to the right, and someones first review of playing the xbox at the local Best Buy. The Yahoo search had a link to the xbox official site, some reviews, cheats, and places to buy it. The Yahoo results are probably what you actually want to see in general.

So far, after a few days of having it up, I find that I keep going back to try out different tags that might bring up interesting results. And because of this, rel8r is a discovery tool, rather than a search. That may sound counter intuitive, but try it to see what I mean. It's got a much more personal feel. Search for the city where you live, search for your name, search for a product you are interested in. And after you do, I'd love to hear your comments and feedback, good or bad.

| | | | | |

It's been a long hiatus from blogging, but I'm back baby... I'm back

A few posts in as many years all the while the little voice in my head kept nagging me to do it more, but I found it hard to get the time to actually sit and get something useful written. I didn't want to just post my comments about other people's blogs, I wanted some real meat to the posts. So anyways, I figure I've got enough stuff crammed into my brain now that I'll start spilling it out.

It starts...