• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changing the mode of a page

 
Luke Murphy
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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?

thanks.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic