Comming from resources.triggerEvent / need to go to another page

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Comming from resources.triggerEvent / need to go to another page

Jochimsen, Janko
Hello,
I am sorry that I need your advice again:
In more than one case I have to use EventBubbling or a call from a JavaScript script to a Component. That looks all very nice but it seems to generate a wired problem. The separation to the Component leads to a situation that the user interaction (directly or via the JS script) will be revived by the component. In my case that interaction should lead to a call of another page.
As we have EventBubbeling in Tapestry I promote the call from the receiving component to the page via

      @Inject
      private ComponentResources resources;

      public boolean  onActionFromShowDetail(ProvinceInFY element) {
            logger.info("Communicate to parent page via EventBubbeling Call for Full View :["+element.getTitle()+"]");
            Long l = element.getId();
            resources.triggerEvent("ShowDetailsViaBubble", new Object[]{l}, null);

           return false;
      }

In the java class for the page I implement the receiving base method this way
public void   onShowDetailsViaBubble(Object[] values) {
            Long l = (Long) values[0];
            long elementid = l;
            logger.info("Bubbled up with id " + elementid);

      }
To that point everything runs fine. But I want to go to another page from here and that seems to be impossible. If I return and Object of a injected Page. I will get an exception saying that this return type is not allowed.

Next I tried:

@InjectPage
DetailUserNice detailPage;


Link link = pageRenderLinkSource.createPageRenderLink(detailPage.getClass());

Directly or in a sub-method.

At one point the console tells me

[INFO] InternalModule.PageLoader Loaded page 'nav/user/DetailUserNice' (it) in 19,247 ms

But then it updates the main page that I want to leave.

Any suggestions?

Thank you in advance.


Janko

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Comming from resources.triggerEvent / need to go to another page

Dimitris Zenios
You need to catch the response of the page event and return it back from
your component handler i.e

On your component

public Object onActionFromShowDetail(ProvinceInFY element) {

    logger.info("Communicate to parent page via EventBubbeling Call
for Full View :["+element.getTitle()+"]");
    Long l = element.getId();
    CaptureResultCallback<Object> resultCallback = new
CaptureResultCallback<>();
    resources.triggerEvent("ShowDetailsViaBubble", new Object[]{l},
resultCallback);

    return resultCallback.getResult();
}


And on your page


@OnEvent(value="ShowDetailsViaBubble")
private Object onShowDetailsViaBubble(long l) {
    return DetailUserNice.class;
}


You don't need to inject the page and use Pagerenderlinksource since you
are not passing any context on that page.

You can return the page class directly.


Dimitris Zenios



On Sun, Jul 24, 2016 at 1:27 AM, Jochimsen, Janko <
[hidden email]> wrote:

> Hello,
> I am sorry that I need your advice again:
> In more than one case I have to use EventBubbling or a call from a
> JavaScript script to a Component. That looks all very nice but it seems to
> generate a wired problem. The separation to the Component leads to a
> situation that the user interaction (directly or via the JS script) will be
> revived by the component. In my case that interaction should lead to a call
> of another page.
> As we have EventBubbeling in Tapestry I promote the call from the
> receiving component to the page via
>
>       @Inject
>       private ComponentResources resources;
>
>       public boolean  onActionFromShowDetail(ProvinceInFY element) {
>             logger.info("Communicate to parent page via EventBubbeling
> Call for Full View :["+element.getTitle()+"]");
>             Long l = element.getId();
>             resources.triggerEvent("ShowDetailsViaBubble", new
> Object[]{l}, null);
>
>            return false;
>       }
>
> In the java class for the page I implement the receiving base method this
> way
> public void   onShowDetailsViaBubble(Object[] values) {
>             Long l = (Long) values[0];
>             long elementid = l;
>             logger.info("Bubbled up with id " + elementid);
>
>       }
> To that point everything runs fine. But I want to go to another page from
> here and that seems to be impossible. If I return and Object of a injected
> Page. I will get an exception saying that this return type is not allowed.
>
> Next I tried:
>
> @InjectPage
> DetailUserNice detailPage;
>
>
> Link link =
> pageRenderLinkSource.createPageRenderLink(detailPage.getClass());
>
> Directly or in a sub-method.
>
> At one point the console tells me
>
> [INFO] InternalModule.PageLoader Loaded page 'nav/user/DetailUserNice'
> (it) in 19,247 ms
>
> But then it updates the main page that I want to leave.
>
> Any suggestions?
>
> Thank you in advance.
>
>
> Janko
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: Comming from resources.triggerEvent / need to go to another page

Jochimsen, Janko
Thanks for the support Demitrits,

Your hint solved one of my problems.

I just have to add that I needed to inject the page and give the Object not just the class in order to pass the elementId.


Now it works for the normal EventBubbeling. From a Component to a Page. What is quite wired is that it does not work for a CallBack from a JavaScript.

Let me explain:

With
        public void afterRender() {
                Link link = resources.createEventLink("Call");
                String uri = link.toAbsoluteURI();
                String output = "Call JS with Parameter:[" + uri + "]";
                logger.info(" Report : " + output);
                javaScriptSupport.require("escBubbleRenderer2").with(uri, data, this.getDivString(), title);
        }


I hand over part of the control to a jqplot element. In order enable this element to call back if the user selects something in the plot the uri variable is given to the JavaScript. Now if the user interacts with the plot the method call gets called. This looks like this:

public Object onCall(@RequestParameter( "params" ) JSONObject eventContext ) {
                if (eventContext != null) {
                        StringBuffer sb = new StringBuffer();
                        int lenght = eventContext.length();
                        String data = eventContext.toString();
                        if (data != null) {
                                sb.append(data + " has " + lenght);
                        } else {
                                sb.append("NO DATA");
                        }
        logger.info("Got Called from JS with data " + sb.toString());
                } else {
                        logger.info("Got Called from JS with data == null");
                }
// some data fetching with the data element to get element and element.Id
CaptureResultCallback<Object> resultCallback = new CaptureResultCallback<Object>();
resources.triggerEvent("ShowDetailsBubble", new Object[]{element.getId()}, resultCallback);
            return resultCallback.getResult();
        }

From the trace I can see that this method gets called. I also see that the page method (see next) gets called:

@OnEvent(value="ShowDetailsBubble")
        private Object onShowDetailsBubble(Object[] values) {
                Long l = (Long) values[0];
                long elementid = l;
                logger.info("Bubbled up with id " + elementid);
                detailPage.setObjectToEdit(elementid);
                detailPage.setJumpBackPage(this);

                return detailPage;
        }

This is exactly the same method that gets called from the other component that works now just fine.

But nothing happens.

So it works from an Event to Component to Page.
But it doesn’t work for JSEvent (via CallBack) to Component to Page

Why?

If you could hind me to any manual or explanation in the web I would try to find it out myself. But all the documentations I could find is rather old and / or does not go this deep into the matter.

Thanks


Janko

-----Ursprüngliche Nachricht-----
Von: Dimitris Zenios [mailto:[hidden email]]
Gesendet: Sonntag, 24. Juli 2016 10:23
An: Tapestry users <[hidden email]>
Betreff: Re: Comming from resources.triggerEvent / need to go to another page

You need to catch the response of the page event and return it back from your component handler i.e

On your component

public Object onActionFromShowDetail(ProvinceInFY element) {

    logger.info("Communicate to parent page via EventBubbeling Call for Full View :["+element.getTitle()+"]");
    Long l = element.getId();
    CaptureResultCallback<Object> resultCallback = new CaptureResultCallback<>();
    resources.triggerEvent("ShowDetailsViaBubble", new Object[]{l}, resultCallback);

    return resultCallback.getResult();
}


And on your page


@OnEvent(value="ShowDetailsViaBubble")
private Object onShowDetailsViaBubble(long l) {
    return DetailUserNice.class;
}


You don't need to inject the page and use Pagerenderlinksource since you are not passing any context on that page.

You can return the page class directly.


Dimitris Zenios



On Sun, Jul 24, 2016 at 1:27 AM, Jochimsen, Janko < [hidden email]> wrote:

> Hello,
> I am sorry that I need your advice again:
> In more than one case I have to use EventBubbling or a call from a
> JavaScript script to a Component. That looks all very nice but it
> seems to generate a wired problem. The separation to the Component
> leads to a situation that the user interaction (directly or via the JS
> script) will be revived by the component. In my case that interaction
> should lead to a call of another page.
> As we have EventBubbeling in Tapestry I promote the call from the
> receiving component to the page via
>
>       @Inject
>       private ComponentResources resources;
>
>       public boolean  onActionFromShowDetail(ProvinceInFY element) {
>             logger.info("Communicate to parent page via EventBubbeling
> Call for Full View :["+element.getTitle()+"]");
>             Long l = element.getId();
>             resources.triggerEvent("ShowDetailsViaBubble", new
> Object[]{l}, null);
>
>            return false;
>       }
>
> In the java class for the page I implement the receiving base method
> this way
> public void   onShowDetailsViaBubble(Object[] values) {
>             Long l = (Long) values[0];
>             long elementid = l;
>             logger.info("Bubbled up with id " + elementid);
>
>       }
> To that point everything runs fine. But I want to go to another page
> from here and that seems to be impossible. If I return and Object of a
> injected Page. I will get an exception saying that this return type is not allowed.
>
> Next I tried:
>
> @InjectPage
> DetailUserNice detailPage;
>
>
> Link link =
> pageRenderLinkSource.createPageRenderLink(detailPage.getClass());
>
> Directly or in a sub-method.
>
> At one point the console tells me
>
> [INFO] InternalModule.PageLoader Loaded page 'nav/user/DetailUserNice'
> (it) in 19,247 ms
>
> But then it updates the main page that I want to leave.
>
> Any suggestions?
>
> Thank you in advance.
>
>
> Janko
>
>

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