Hi, Alex!

Thanks for your reply, this was really helpful to understand more about
event processing.

Though, I don't like this approach for my use case for several reasons:
1) ComponentRequestFilter gets executed for every component/page event in
application, while I want this only for single page
2) There's no API in ComponentRequestFilter that allows substitute response
without invoking event handler

What I ended with is I provided custom ComponentClassTransformWorker2 that
can take handle this code (I reused @Advise and @Match annotations to bind
methods):

    private static final String ENSURE_PROJECT_EXISTS =
"ensureProjectExists";

    @Advise(id=ENSURE_PROJECT_EXISTS)
    public Object interceptEvent(MethodInvocation invocation)
    {
        if (project == null)
        {
            int projectId = (Integer) invocation.getParameter(0);

            Object response = resolveProject(projectId);
            if (project == null) {
                return response;
            }
        }
        return null;
    }

    @Match(ENSURE_PROJECT_EXISTS)
    public Object onActionFromCheckout(int projectId)
    {
        projectManager.scheduleCheckout(project);

        return settingsBlock;
    }

    @Match(ENSURE_PROJECT_EXISTS)
    public Object onActionFromUpdate(int projectId)
    {
        projectManager.scheduleUpdate(project);

        return settingsBlock;
    }


On Tue, Aug 7, 2012 at 12:00 AM, Alex Kotchnev <akoch...@gmail.com> wrote:

> Dmitry,
>    there is the import
> org.apache.tapestry5.services.ComponentRequestFilter, which gets called on
> page and component events. For example, Tynamo's tapestry-security module
> (e.g. org.tynamo.security.SecurityComponentRequestFilter) uses these to
> check if the user has the correct permissions.
>
>    Maybe this is too obvious of an answer and you're looking for something
> else...
>
> Cheers,
>
> Alex K
>
> On Mon, Aug 6, 2012 at 3:52 PM, Dmitry Gusev <dmitry.gu...@gmail.com>
> wrote:
>
> > Hi,
> >
> > is it possible to intercept component event actions?
> >
> > I have one page with multiple zones. Blocks from another page rendered on
> > these zones using ajax.
> > Those blocks have components with event action handlers.
> > Every action handler have context parameter, and I would like to check
> > these params before action gets executed and, possibly, substitute
> another
> > action output.
> >
> > Normally I'd use page's onActivate method for this, but since blocks are
> on
> > the other page -- onActivate doesn't get invoked for that page.
> > Now I have to repeat the code in order to do checks (see code below), but
> > I'd really like to intercept these calls.
> >
> > Just can't find how to do this. Or I'm I doing something wrong and this
> can
> > be done in some other way?
> >
> > public class PageWithBlocks {
> >
> >     private Project project;
> >
> >     ...
> >
> >     public Object onActionFromCheckout(int projectId) {
> >         //  XXX Code smells (DRY)
> >         if (project == null)
> >         {
> >             Object response = resolveProject(projectId);
> >             if (project == null) {
> >                 return response;
> >             }
> >         }
> >
> >         projectManager.scheduleCheckout(project);
> >
> >         return settingsBlock;
> >     }
> >
> >     public Object onActionFromUpdate(int projectId) {
> >         //  XXX Code smells (DRY)
> >         if (project == null)
> >         {
> >             Object response = resolveProject(projectId);
> >             if (project == null) {
> >                 return response;
> >             }
> >         }
> >
> >         projectManager.scheduleUpdate(project);
> >
> >         return settingsBlock;
> >     }
> > }
> >
> > --
> > Dmitry Gusev
> >
> > AnjLab Team
> > http://anjlab.com
> >
>



-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Reply via email to