Data AccessCore JavaApp FrameworksViewTestingBuildingDeploymentDev ToolsSecurityOpinions

Monday, July 6, 2009

Preparable CRUD actions with multiple prepare methods

Many of the Struts2 Tutorials guide you towards stuffing multiple CRUD operations for a single entity within a single action. Sounds nice, but what happens when you need to prepare these actions differently?

Your first instinct might tell you to implement multiple actions for that one entity (one per CRUD operation, or maybe even stuff two inside one action).

However, you can add multiple prepare{METHOD}() like prepareDoDelete(),
prepareDoUpdate(). If you follow this convention, the appropriate prepare method will be called before your action method.

The following is a snippet from the Struts 2 Documentation at:
http://struts.apache.org/2.0.11/docs/prepare-interceptor.html

In PrepareInterceptor

Applies only when action implements Preparable

1. if the action class have prepare{MethodName}(), it will be invoked
2. else if the action class have prepareDo(MethodName()}(), it will be invoked
3. no matter if 1] or 2] is performed, if alwaysinvokePrepare property of the interceptor is "true" (which is by default "true"), prepare() will be invoked.

4 comments:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

    Online Java Training Java Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai

    ReplyDelete
  2. The outcome is an amazingly adaptable payback plan. On the off chance that you have an awful month, you may battle to influence the installment on your customary business to credit, online Check Cashing Chula vista

    ReplyDelete