File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes changing the mode of a page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "changing the mode of a page" Watch "changing the mode of a page" New topic

changing the mode of a page

Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
I am using JSF 2.0.
I am doing a standard create / read / update / delete for various entities e.g. tennis balls, toasters and cars.
I would like to use the one page for the create, read, update and delete for each entity and just change the mode of it based on the use case.

Anyone got a link to a good tutorial for this?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

I'm assuming that you have a separate detail edit page for each entity type. It can get really complicated if you attempt to dynamically create an editor from a one-size-fits-all page. And I have code to prove it (it's a generic database editor app, incidentally).

I normally have "begin" methods that lay the groundwork and are invoked by the referring page's action method, so the "from" page (which is typically a tabular view) will invoke "beginAdd" or "beginEdit" and that will be where the intialization is done and where I set my processing mode indicator. I use the common practice of putting a delete button on the Edit view, so there's no separate "delete" mode. For Display (read) mode, I typically just use an alternative view definition using display-only controls, since it generally looks better.

You can do everything you want with only 1 or 2 view definitions (depending on whether you have a separate Display view). I return the captions for the buttons based on the add/edit mode indicator, as well as show/hide controls (obviously "delete" doesn't need to be there if you're still adding it). The actual storage commit action I normally simply name "doSave" and it invokes add or update logic depending on mode. The Delete button is an immediate button with a confirmation JavaScript ("Are you sure?") popup attached to it.

Because this stuff is so generic, I often machine-generate the prototypes straight from my domain model definitions, then hand-tweak as needed.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: changing the mode of a page
It's not a secret anymore!