On 7/12/05, Rick Reumann <[EMAIL PROTECTED]> wrote:
> I was just replying to a post about keeping your Actions clean and doing
> the business logic in other classes.
> 
> One thing I didn't bring up, though, because I'm not sure how 'best
> practice' it is, is the concept of passing your ActionForm and sometimes
> the HttpServletRequest off to another class for some processing. I'm
> doing that a bit in this app I'm currently working on and I'm liking it.

I do not pass a whole form, but I pass stuff like session object into
login/signup module, which stores current login name in session.

> Possibly all of this is overkill, but it came about based on a real use
> case. The situation is when CRUD operations are selected from the form,
> the type of Value Object created and the type of Service that gets
> called is based on a requirement passed in by the form. What gets done
> when the form is submitted can be very different based on the type of
> object being represented when the form submits, so I needed a way to get
> a unique type of Service/Delegate base on the ID. I found it clean to
> isolate all of this from the Action, so the Action method looks like...
> 
> update(..) {
> MyForm myForm = (MyForm)form;
> ServiceFactory.getService( myForm.getTypeID ).update( myForm );
> //other stuff
> 
> Now since the correct Service is obtained, it can do the copying of
> proeprties to the unique value object and can call the approrpriate DAO
> that is in that service class.

My CRUDAction saves data like this:

    public ActionForward onSave (...) {
        ActionMessages messages = form.validate(mapping, request);

        // Invalid input data
        if (messages != null && !messages.isEmpty()) {
            session.setAttribute(Globals.ERROR_KEY, messages);
            return mapping.findForward(MAPPING_ON_INVALID_DATA);

        // Input data is valid
        } else {

            // Try to persist form data
            ICRUDForm crudForm = (ICRUDForm) form;
            ActionMessages storeMessages = crudForm.crudStore();

            // Could not persist form data
            if (storeMessages != null && !storeMessages.isEmpty()) {
                session.setAttribute(Globals.ERROR_KEY, storeMessages);
                return mapping.findForward(MAPPING_ON_STORE_FAILURE);

            // Successfully persisted
            } else {
                return mapping.findForward(MAPPING_ON_STORE_SUCCESS);
            }
        }
    }

DAO/database/ORM/whatever is accessed in crudForm.crudStore(). It
calls either method on nested BO, or calls DAO layer. Yes, from an
action form, but you already know this ;)

Michael.

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

Reply via email to