Tuesday, August 25, 2009

Richfaces: immediate vs bypassUpdates attributes

If you are familiar with JSF then you know when to use immediate attribute. If not, here is a quick refresher. JSF has six different phases:
  1. Restore View - Creates or restores the previous page.

  2. Apply Request Values - Set component submitted values to request values.

  3. Process Validations - Convert and validate component values. Set component values to submitted values if valid.

  4. Update Model Values - Set backing bean values to component values.

  5. Invoke Application - Execute actionListeners and actions.

  6. Render Response - Return response.

When immediate is set to true, action components call navigation handler just after 2nd phase and skip 3-5 phases. The most common usecase is with cancel button on a form i.e. when user clicks on Cancel button, you don't want to force user to enter correct values.

Now with bypassUpdates attribute, only 4-5 phases are skipped; validation happens as usual. To credit Nick Belaevski for giving a concrete example of a sign up form, you can have one button in form to cancel (set immediate=true) and another checks whether screenname is already taken (set bypassUpdates=true). Obviously, setting both to true for same component does not make sense. If you are still not clear, here is code snippet from org. ajax4jsf.component.AjaxActionComponent
if (event instanceof ActionEvent) {
if (event.getComponent() == this) {
if (isImmediate()) {
event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
} else if (isBypassUpdates()) {
event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
} else {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
}
}
// UICommand set Phase ID for all ActionEvents - bypass it.
getParent().queueEvent(event);
}
It should be crystal clear now...at least it was for me.

Tuesday, August 4, 2009

Now you can tweet from JBoss Portal

Introducing Twitter portlet for JBoss Portal and Enterprise Portal platform. It's based on twitter4j, Richfaces, JBoss Portlet Bridge.

Using this portlet, you can
  • Update your status
  • Get messages that are sent directly to you (e.g. @prabhatjha in my case)
  • Get list of folks who you are following and get their latest status. List is sortable.
I would say that this is basic but my goal was to have something for folks to get started with. twitter4j exposes various twitter api which you can use to customize this portlet for your need. I will leave that as an exercise for reader (I always wanted to say that ;-) ) Here are some screen shots:





You can grab the code from http://anonsvn.jboss.org/repos/qa/prabhat/twitter-portlet/ But this portlet can very well run on other portal servers as well if you know what deployment descriptors you need to modify.