|
|
|||||
Ed Burns's BlogRepost: Bringing Ruby on Rails's Flash to JSFPosted by edburns on March 01, 2006 at 12:20 PM | Comments (5)With the demise of the Sun Engineer's Sandbox, my content posted there has disappeared. Thankfully I saved a copy. Thanks to srcerer on the ##jsf chat room on freenode for reminding me to repost this. OverviewTo celebrate the release of Ruby on Rails (RoR) 1.0, I have taken the
flash
concept from Rails's Figure 1 is a cheesy graphical depiction of the request, flash, dialog, session, and application scopes.
The nice thing about these scopes is that they all have a Map into which you can stick things. These Maps have the special property that they will be cleared when the scope ends. In the case of the flash, the map is cleared after exactly two runs through the JSF request processing lifecycle. I included Shale's Dialog concept for good measure since I believe this concept is important to the future of JSF For example, it's so important that JBoss Seam also provides a similar concept. A Shale dialog or Seam conversation is a scope whose length is determined by the application developer. BackgroundOf course, I needed a release-vehicle for this thing so I created a new glassfish sub-project on java.net called jsf-extensions. My intent is to use this project for a number of extensions to the core jsf implementation. The flash is just the first the first that is ready for public use. Others in the works include:
But enough about the future of Getting Started
App TraversalThis app illustrates using the Flash from JSP. It is also possible to use the flash directly from Java Code, or via the EL API. These latter two methods are described in the JavaDocs. As you may know from Jennifer
and Pierre's article on the Unified EL, JSF expressions can be
accessed in a "get" context, or a "set context", otherwise known as
"rvalue" or "lvalue", respectively. Thefore, the EL Expression
In JSP pages, most expressions act as rvalues, whereas the lvalue
behavior does not occurr until the form is submitted and the values
entered by the user are stored into the expressions. However, to make
it easier to set expression values from JSP, including setting into the
flash, the jsf-extensions library includes the
We're using the panelGrid tag (in way we not possible before JSF 1.2,
due to the problems pointed out in Hans
Bergsten challenge) to lay out the contents in a simple two column
table. The first row shows the use of the If you want to store something in the flash for use on this request, click on the "next" button in the sample app for an example. In this page we use the "flash.now" syntax, shown below in JSP.
By inserting the special keyword "now" we tell the flash that this store operation should be accessible on this request, rather than the next request. If, during processing, you decide you want to promote the value from flash.now to the real flash, use "flash.next" as shown on the next page of the sample app.
When you click on the next button, you will be shown a page that shows that the value in the flash has indeed survived the postback.
This is a brief introduction to using the flash, a more in-depth article would cover a common real-world use-case, such as doing master-detail, and also cover the other two entry points to using the flash, the EL API, and direct programmatic use. Technorati Tags: edburns Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment
| |||||
|
|