Monday, October 19, 2009

Spring Web Flow with Pop-Up View States

Setting up an application that uses pop-up view states with a JSF view has worked very well, except for the pop-ups; I had to spend a while on trying to make them work and had been barking up a forest of wrong trees before I finally got to downloading the "booking-jsf" sample from Spring Source Download (highly recommended, something I should have started from), and went to compare the configuration. The important points:

(1) Follow the Spring Web Flow reference for setting up Facelets and Web Flow integration

(2) The view state that uses the pop-up should be also explicitly rendering a part of the view (one doesn't need the whole in the modal window; the page itself, on the other hand, should be complete, so as to degrade gracefully and display even when pop-ups are disabled)

<view-state id="selectFiles" view="/files-select.xhtml" popup="true" redirect="true">
  <on-entry>
   <render fragments="content-area-popup"></render>
  </on-entry>
    ...
 </view-state> 

(if anyone noticed the "redirect", more on that later)

(3) Make sure the view that invokes the popup uses "sf:commandButton", and not normal JSF/Tomahawk/WhateverLibrary tag that one uses for buttons

...
 <sf:commandButton value="Add Another" action="selectFiles"/>
...

(4) Finally, make sure the transition uses "redirect"; normally, this is the default, but, in my case, I have disabled it in the flow engine configuration (need to use legacy JSF views that persist state using "t:saveState"); if disabled, redirect transition can be enabled by "redirect='true'" view definition attribute in the flow definition

It is the failure to ensure (4) that was making my popup to either not display or produce obscure errors, as the flow view rendering was trying to render the popup inside the invoking screen and was missing the element with the same ID to replace with the popup content.

No comments: