Michael Jouravlev wrote:
After you filled in the form, you call EntityAction with "store"
command. It validates the input and then tries to update/store data.
If input is not valid, the action checks the state field and forward
to a JSP that corresponds to that state. The page will be displayed
along with the errors. If data is saved successfully, you forward to
your success page, which is probably the item list. Same with
deletion, after "delete" event is served, you forward to success page.

Right, but the difficulty here is that the validation then has to be done in the action, and I can't rely on the 'validate="true"' to use ValidatorForm's validate() method and dump my simple, non-database-reliant validations into validations.xml.

Here's what I'm doing for all my entities (things are bound to get more complex, as for now I'm just doing an "admin" module, which is pretty isolated against everything else, but I'll cross those bridges once I get to them):

I have a class called EntityAction (extends DispatchAction). It has the following actions:
   - newEntity: Clears the request form and forwards to create_entity.jsp
- createEntity: Creates the entity in the database and forwards to edit_entity.jsp - updateEntity: Updates the entity in the database and forwards to edit_entity.jsp - retrieveEntity: Gets the entity out of the database, populates the form and forwards to edit_entity.jsp - deleteEntity: Deletes the entity from the database, and forwards to create_entity.jsp

This is far, far cleaner than the approach I was using before I read these e-mails :). Additionally, I use exactly one form for this process.

A little trickery starts to appear when I have a child entity. Now I have to make the following modifications:

- newChild, createChild: Needs to redirect to parents.jsp if no parent key is supplied - updateChild, retrieveChild, deleteChild: Needs to redirect to parents.jsp if child key not supplied or found

I also need to accommodate for a valid child key being specified without a parent key, as I can correct this by populating the parent key from the database. Fun stuff :).

Anyways, what I may do is some kind of hybrid form/validation where the action validates the form and determines the appropriate forward on failure. My only issue is the one mentioned above, where I'm not sure how to hook this into the validator mechanism.

I love this stuff (especially the whole "find the best way to do something you can already technically do," I just wish I knew more about it...

Thanks!

- Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to