onActivate not being triggered

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

onActivate not being triggered

nhhockeyplayer
Hi Folks,

I have this code...

    @InjectPage
    private MetaTagEdit metaTagEditPage;
   
    @OnEvent(EventConstants.ACTIVATE)
    //void onActivate(Class clazz, long id)    
    //void activate(Class clazz, long id)    
    //Object activate(Class clazz, long id)
    //Object activate(Class clazz, Long id)
    Object activate(Class clazz, Object bean, Integer id)
    {
        if (clazz == null)
            return Utils.new404(messages);
        this.bean = contextValueEncoder.toValue(clazz, id.toString());
        this.beanType = clazz;
        if (bean == null)
            return Utils.new404(messages);
        return null;
    }

    @OnEvent(EventConstants.PASSIVATE)
    Object[] passivate()
    {
        return new Object[]
        { beanType,  bean, ((MetaTag) bean).getId() };
    }

nothing above works.

I cant get onActivate to trigger for anything.

I also tried renaming the methods with "on" prefix using camelCase

Any tips are appreciated.

I am breakpoint blue in the face

KEN
     
Best regards and thanks
Ken
Reply | Threaded
Open this post in threaded view
|

Re: onActivate not being triggered

Chris Poulsen
If the actual arguments does not fit the signature the handler will be
skipped (the rules can be found in the docs).

Try: Object onActivate( EventContext ec )

to see what is acutally getting passed as context.


On Fri, Oct 31, 2014 at 3:21 PM, nhhockeyplayer nashua <
[hidden email]> wrote:

> Hi Folks,
>
> I have this code...
>
>     @InjectPage
>     private MetaTagEdit metaTagEditPage;
>
>     @OnEvent(EventConstants.ACTIVATE)
>     //void onActivate(Class clazz, long id)
>     //void activate(Class clazz, long id)
>     //Object activate(Class clazz, long id)
>     //Object activate(Class clazz, Long id)
>     Object activate(Class clazz, Object bean, Integer id)
>     {
>         if (clazz == null)
>             return Utils.new404(messages);
>         this.bean = contextValueEncoder.toValue(clazz, id.toString());
>         this.beanType = clazz;
>         if (bean == null)
>             return Utils.new404(messages);
>         return null;
>     }
>
>     @OnEvent(EventConstants.PASSIVATE)
>     Object[] passivate()
>     {
>         return new Object[]
>         { beanType,  bean, ((MetaTag) bean).getId() };
>     }
>
> nothing above works.
>
> I cant get onActivate to trigger for anything.
>
> I also tried renaming the methods with "on" prefix using camelCase
>
> Any tips are appreciated.
>
> I am breakpoint blue in the face
>
> KEN
>
Reply | Threaded
Open this post in threaded view
|

Re: onActivate not being triggered

Thiago H de Paula Figueiredo
On Fri, 31 Oct 2014 12:29:16 -0200, Chris Poulsen <[hidden email]>  
wrote:

> If the actual arguments does not fit the signature the handler will be
> skipped (the rules can be found in the docs).
>
> Try: Object onActivate( EventContext ec )
>
> to see what is acutally getting passed as context.

Actually, I'd consider onActivate(EventContext) the recommended way of  
receiving the activation context. It's *always* called. No surprises. :)  
In Ken's case, I'd guess there's no String to Class and String to Object  
coercions contributed to TypeCoercer.

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: onActivate not being triggered

Lance Java
In reply to this post by nhhockeyplayer
Tapestry seems magic at times but it can't read your mind unfortunately.
How on earth would tapestry know what to instantiate for Object?
Reply | Threaded
Open this post in threaded view
|

Re: onActivate not being triggered

Thiago H de Paula Figueiredo
On Fri, 31 Oct 2014 13:31:54 -0200, Lance Java <[hidden email]>  
wrote:

> Tapestry seems magic at times but it can't read your mind unfortunately.

Tapestry is magic, not psychic! (tm) :D

> How on earth would tapestry know what to instantiate for Object?

Impossible, unless, of course, your contribute a ValueEncoder<Object> for  
the ValueEncoderSource service, but then it's your code handling that, not  
Tapestry itself. :)

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: onActivate not being triggered

nhhockeyplayer
In reply to this post by nhhockeyplayer
Chris,

Thanks

I put what you stated... and triggered finally my breakpoint.

This is whats inside eventcontext

<EventContext: 1>

Now what ?
     
Best regards and thanks
Ken
Reply | Threaded
Open this post in threaded view
|

RE: onActivate not being triggered

nhhockeyplayer
I had to say...

I got breakpoints on both passivate and activate

ONLY activate is being triggered

And I am not receiving what I need in my eventcontext object

Not sure what to think at this point

the tynamo guys had a List.java module that is used and replicated as a page. At one point I was using eclipse and performed SHIFT-O which poulated my java module with package references... and without glancing I just grabbed the first one atop the list since it said "java.util.List" and being a dimbo java developer I just said ok... I will use that one. But who deserves the hard dope slap... me or the person who designed List.java ? Since then I have browsed all my pages and such threatening lapses in type usages which caused horrific runtime issues.

Still not sure what to think at this point

Any ideas ? I fixed the activate being triggered... but the EventContext object is not delivering for me.

My new problem is passivate is not being triggered.

Thanks
     
Best regards and thanks
Ken
Reply | Threaded
Open this post in threaded view
|

Re: onActivate not being triggered

Thiago H de Paula Figueiredo
In reply to this post by nhhockeyplayer
On Sat, 01 Nov 2014 08:20:20 -0200, nhhockeyplayer nashua  
<[hidden email]> wrote:

> This is whats inside eventcontext
>
> <EventContext: 1>

Have you tried its getCount() and get(Class, int) methods?

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: onActivate not being triggered

Thiago H de Paula Figueiredo
In reply to this post by nhhockeyplayer
On Sat, 01 Nov 2014 09:07:10 -0200, nhhockeyplayer nashua  
<[hidden email]> wrote:

> the tynamo guys had a List.java module

Link to it please? I have no idea what you're talking about.

> Any ideas ? I fixed the activate being triggered... but the EventContext  
> object is not delivering for me.

EventContext will provide you whatever context was passed to your page.

> My new problem is passivate is not being triggered.

Now this is weird. Your method looks ok to me:

@OnEvent(EventConstants.PASSIVATE)
Object[] passivate() {
         return new Object[] { beanType,  bean, ((MetaTag) bean).getId() };
}

Have you tried renaming it to onPassivate()? Remember onPassivate() is  
only called when Tapestry needs to create a link to that page (event  
links, for example). How are you getting to the page?

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: onActivate not being triggered

nhhockeyplayer
In reply to this post by nhhockeyplayer
Thanks Thiago for your help

Ok List.JAVA is located under the pages directory

https://github.com/tynamo/tapestry-model/blob/master/tapestry-model-example/src/main/java/org/tynamo/examples/simple/pages/List.java

This is one typical sample app that uses it. Its identical to the one I use. If your not careful you can get caught up with package includes colliding with "java.util.List"

my package includes are resolved as this was posing a problem for me week sback unknowingly... and I am sure back in June 2013

this is not the cause or blame for my issue

My issue being I cannot get the edit page to feed back to the show page.
     
Best regards and thanks
Ken
Reply | Threaded
Open this post in threaded view
|

RE: onActivate not being triggered

nhhockeyplayer
Hi Thiago,

I changed passivate to onPassivate... and no change

I did notice that

activate gets called once
passivate gets called 5 times
cleanup gets called once
passivate gets called 6 times
activate gets called once

and thats the end... in that order

and my URL is

http://localhost:8080/psi/metatag/1

but strangely what is on the browsers page is

http://localhost:8080/psi/edit/photogroupphoto

displaying some photo of a different blob business object

Not sure what to think



     
Best regards and thanks
Ken
Reply | Threaded
Open this post in threaded view
|

RE: onActivate not being triggered

nhhockeyplayer
package org.tynamo.examples.psi.pages.edit;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.CleanupRender;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.ContextValueEncoder;
import org.apache.tapestry5.services.PageRenderLinkSource;
import org.tynamo.examples.psi.CustomCommitAfter;
import org.tynamo.examples.psi.model.MetaTag;
import org.tynamo.examples.psi.pages.Show;
import org.tynamo.routing.annotations.At;
import org.tynamo.services.PersistenceService;
import org.tynamo.util.TynamoMessages;
import org.tynamo.util.Utils;

/**
 * Page for editing and updating objects.
 *
 * @note: When extending this page for customization purposes, it's better to
 *        copy & paste code than trying to use inheritance.
 *
 */

@RequiresUser
@RequiresAuthentication
@At("/{0}/edit")
public class MetaTagEdit
{
    @Inject
    private ContextValueEncoder contextValueEncoder;

    @Inject
    private Messages messages;

    @Inject
    private PersistenceService persistenceService;

    @Inject
    private PageRenderLinkSource pageRenderLinkSource;

    @Property(write = false)
    private Class beanType = MetaTag.class;

    @Property
    private Object bean;

    private boolean continueEditing;

    @InjectPage
    private MetaTagEdit metaTagEditPage;
   
    @OnEvent(EventConstants.ACTIVATE)
    //void onActivate(Class clazz, long id)    
    //void activate(Class clazz, long id)    
    //Object activate(Class clazz, long id)
    //Object activate(Class clazz, Long id)
    //Object onActivate(Class clazz, Object bean, Integer id)
    Object activate( int id )
    {
        Class clazz = MetaTag.class;
        if (clazz == null)
            return Utils.new404(messages);
        this.bean = contextValueEncoder.toValue(clazz, new Integer (id).toString());
        this.beanType = clazz;
        if (bean == null)
            return Utils.new404(messages);
        return null;
    }

    /*
     * void onActivate() { this.bean =
     * contextValueEncoder.toValue(MetaTag.class, id.toString()); this.beanType
     * = MetaTag.class;
     *
     * beanModel = beanModelSource.createEditModel(beanType, messages); }
     */
    @OnEvent(EventConstants.PASSIVATE)
    Object[] onPassivate()
    {
        return new Object[]
        { ((MetaTag) bean).getId() };
    }

    @CleanupRender
    void cleanup()
    {
        bean = null;
        beanType = null;
    }

    @OnEvent(value = "return")
    void onSaveAndReturn()
    {
        this.continueEditing = false;
    }

    @OnEvent(value = "stay")
    void onSaveAndContinue()
    {
        this.continueEditing = true;
    }

    @Log
    @CustomCommitAfter
    @OnEvent(EventConstants.SUCCESS)
    Link success()
    {
        persistenceService.save(bean);
        return !continueEditing ? back() : null;
    }

    @OnEvent("cancel")
    Link back()
    {
        return pageRenderLinkSource.createPageRenderLinkWithContext(Show.class, beanType, bean);
    }

    public String getListAllLinkMessage()
    {
        return TynamoMessages.listAll(messages, beanType);
    }

    public String getTitle()
    {
        return TynamoMessages.edit(messages, beanType);
    }

}

     
Best regards and thanks
Ken
Reply | Threaded
Open this post in threaded view
|

RE: onActivate not being triggered

nhhockeyplayer
I got the event handlers triggering now... not that I am comfortable with what thr runtime is doing under the hood

I wanted to restate my issue

During EDIT with this EDIT Page

on OK or CANCEL

my browser URL looks like
http://localhost:8080/psi/metatag/1

but strangely what is on the browsers display is and this is confirmed by the bottom status bar of th ebrowser

http://localhost:8080/psi/edit/photogroupphoto

displaying some photo of a different blob business object

So the OK and CANCEL action handlers are here

        @Log
        @CustomCommitAfter
        @OnEvent(EventConstants.SUCCESS)
        Link success()
        {
                persistenceService.save(bean);
                return !continueEditing ? back() : null;
        }

        @OnEvent("cancel")
        Link back()
        {
                return pageRenderLinkSource.createPageRenderLinkWithContext(Show.class, beanType, bean);
        }

if I put List.class in place of Show.class, it finds its way back to the List page

My problem being, the edit page is unable to find its way back to the Show page

I dont know why the URL's are messed up for the content and the browser URL address,
the URL address appears to be in order but like I said something is going on under the hood displaying bogus content


Not sure what to think

Any tips are appreciated

     
Best regards and thanks
Ken