Jeromy Evans on 01/05/08 14:49, wrote:
That way you could remove all the boilerplate from your actions.

eg, If it placed the model into the actioncontext you could potentially use
<s:select name="state" list="#states"/>
without your action providing the list or getter at all (except something must instruct the interceptor to load it).
Just some ideas.

I thought about putting it all in the interceptor but I think it could get unwieldy once the application grows.

Plus, there may be logic in the list call to restrict the list in some way. I guess you could do that in an interceptor by casting your action to what you know it is and then calling the required methods on your model.

My boiler plate code isn't so bad, and in fact the only boiler plate stuff is the catch block.

By the way, how would you figure out what the method being called is? Hard-code a call to fetch anything prefixed "method:" from the HTTP params? Or is there something on the Struts API already?

Is there an easier way?

String method = ServletActionContext.getActionContext(request).getActionInvocation().getProxy().getMethod();

That's the right place. It's available as an argument in the intercetpor. PrepareInterceptor is doing exactly that when it looks for the presence of the Preparable interface on your action, and then for a methods matching the prepare<methodName>() signature.

In that case, I shall ditch PrepareInterceptor and code another, along with an interface for the action to implements:

interface DropdownListHelper {
    prepareDropdowns(String methodName);
}

I'll pull the error handling into the interceptor as well, and then all I need in the Action.prepareDropdowns() is a couple of if switchblocks to call the right managers:

public void prepareDropdowns(String methodName)
{
    if (methodName.equals("read")
        || (methodName.equals("save") && hasErrors()))
    {
        getRequest().setAttribute(
            WildlifeJstlConstants.DROPDOWN_SPECIES_HABITAT.toString(),
            habitatManager.search(0, 0));
    }
}

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

Reply via email to