Hi

I'd say that you were off track. Tapestry already provides you with the
means to do what you need (the mentioned ajaxResponseRenderer callback for
ajax requests), so attempting to manipulate the environment to achieve what
is already supported, sounds like the recipe for creating something that
may break on a tapestry upgrade etc.

I can't say what the "intended" purpose of the t:trigger is, but as far as
I can tell from our codebase we mostly use it to plug in behavior
(essentially manipulating the markup writer) at specific points during
template rendering (and we have almost no usages). Almost all the usages we
have seems to be related to making sure that informal parameters end up on
the correct html element.

HTH.

-- 
Chris


On Thu, Sep 27, 2018 at 3:47 PM Davide Vecchi <d...@amcbanking.com> wrote:

> Thanks guys, that was it. Worked right away.
>
> Now my problem is solved, but I'm wondering how off-track I was when I
> thought that the Trigger component was the way to go about this. Is Trigger
> intended for different situations, or is it just another possible
> appropriate way of solving this problem, or would it have been possible to
> solve this using Trigger but it wouldn't have been the right way ?
>
> In any case, as usual I solved my problem by asking here, thanks again.
>
>
> -----Original Message-----
> From: JumpStart <geoff.callender.jumpst...@gmail.com>
> Sent: Thursday, September 27, 2018 14:21
> To: Tapestry users <users@tapestry.apache.org>
> Subject: Re: Using JavaScript during Ajax request
>
> An example:
>
>
> http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/modal/1
> <
> http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/modal/1
> >
>
>
> > On 27 Sep 2018, at 7:06 pm, Nathan Quirynen <nat...@pensionarchitects.be>
> wrote:
> >
> > When your request is an ajax call, you can use the following construct
> to use the JavaScriptSupport service:
> >
> > ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
> >             @Override
> >             public void run(JavaScriptSupport javascriptSupport) {
> >
> >                 // Your code here
> >
> >             }
> > }
> >
> >
> > Op 27/09/2018 om 10:59 schreef Davide Vecchi:
> >> Hello everybody,
> >>
> >> I am having exactly the same problem described in the thread linked
> >> below, that is the exception
> >>
> >> "No object of type
> org.apache.tapestry5.services.javascript.JavaScriptSupport is available
> from the Environment"
> >>
> >> that occurs only if the event handler is handling an Ajax request:
> >>
> >> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/No
> >> -object-of-type-org-apache-tapestry5-services-javascript-JavaScriptSu
> >> pport-is-available-from-the-E-tp5551633p5551729.html
> >>
> >> My stacktrace is at the bottom of this email.
> >>
> >> The event being handled in my case is the click on an EventLink that
> has its t:zone attribute set to the name of a zone.
> >>
> >> In that thread jochenfrey explains that he solved the problem using the
> Trigger component to "get Tapestry Initializer Calls into the Response",
> which I think is what I need as well.
> >>
> >> However, I don't know where in the template the <trigger> tag must be
> placed. I'm also not sure what the event handler of the trigger should do
> in order to provide JavaScript to the EventLink handler. So those are my
> two questions.
> >>
> >> My understanding is that the Trigger event handler should push the
> JavaScriptSupport instance on the stack, so I do:
> >>
> >> environment.push(JavaScriptSupport.class, javaScriptSupport);
> >>
> >> but I'm not sure that's what is needed, and anyway it doesn't work for
> me, it get that exception.
> >>
> >> I have put the <trigger> tag immediately after the opening tag of the
> zone the EventLink is bound to:
> >>
> >>
> >> =====================================================================
> >> ===
> >>
> >> <t:zone id="myBoundZone" >
> >>
> >> <t:trigger event="javaScriptNeeded" />
> >>
> >> ......
> >> </t:zone>
> >>
> >>                 <form t:type="form" t:id="mainForm">
> >>
> >>             <t:zone t:id="mainZone1">
> >>
> >>                   ......
> >>
> >>                   <t:zone t:id="mainZone2">
> >>
> >>                         ......
> >>                         <t:eventlink t:id="myLink" t:zone="myBoundZone"
> >
> >>                               Click me.
> >> </t:eventlink>
> >>
> >>             </t:zone>
> >>
> >> </t:zone>
> >>
> >>       </form>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> -------------------------------------------------
> >>
> >>        @Environmental
> >>        private JavaScriptSupport javaScriptSupport;
> >>
> >>        @Inject
> >>        private Environment environment;
> >>
> >>        void onJavaScriptNeeded()
> >>        {
> >>               this.environment.push(JavaScriptSupport.class,
> this.javaScriptSupport);
> >>        }
> >>
> >>
> >> =====================================================================
> >> ===
> >>
> >> I don't know if the following matters, however:
> >>
> >>
> >>   *   The zone the EventLink is bound to is defined only in the
> template (in the Java code I never need to return that zone from any method
> or do anything with it so I did not create any Zone field for that zone).
> >>
> >>
> >>   *   In the template, the EventLink is itself inside a zone, which is
> nested inside another zone.
> >>
> >>
> >>
> >>   *   The "javaScriptNeeded"  event occurs when the page is loaded. It
> does not occur when I click the link.
> >>
> >>
> >> Thanks for any possible hint.
> >>
> >>
> >> org.apache.tapestry5.ioc.util.UnknownValueException: No object of type
> org.apache.tapestry5.services.javascript.JavaScriptSupport is available
> from the Environment.
> >>                 at
> org.apache.tapestry5.internal.services.EnvironmentImpl.peekRequired(EnvironmentImpl.java:96)
> >>                 at $Environment_4a157190551.peekRequired(Unknown Source)
> >>                 at $Environment_4a157190347.peekRequired(Unknown Source)
> >>                 at
> org.apache.tapestry5.internal.transform.EnvironmentalWorker$EnvironmentalConduit.get(EnvironmentalWorker.java:59)
> >>                 at
> mypackage.tapestry.pages.main.MyPage.conduit_get_javaScriptSupport(MyPage.java)
> >>                 at
> mypackage.tapestry.pages.main.MyPage.onMyLink(MyPage.java:814)
> >>                 at
> mypackage.tapestry.pages.main.MyPage.dispatchComponentEvent(MyPage.java)
> >>                 at
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:917)
> >>                 at
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1102)
> >>                 at
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$3100(ComponentPageElementImpl.java:57)
> >>                 at
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1047)
> >>                 at
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1044)
> >>                 at
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:82)
> >>                 at
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:72)
> >>                 at
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1260)
> >>                 at
> org.apache.tapestry5.internal.structure.ComponentPageElementResourcesImpl.invoke(ComponentPageElementResourcesImpl.java:154)
> >>                 at
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1043)
> >>                 at
> org.apache.tapestry5.internal.services.AjaxComponentEventRequestHandler.handle(AjaxComponentEventRequestHandler.java:110)
> >>                 at
> org.apache.tapestry5.internal.services.ajax.AjaxFormUpdateFilter.handle(AjaxFormUpdateFilter.java:56)
> >>                 at
> $ComponentEventRequestHandler_4a157190730.handle(Unknown Source)
> >>                 at
> $ComponentEventRequestHandler_4a157190574.handle(Unknown Source)
> >>                 at
> org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
> >>                 at
> $ComponentEventRequestHandler_4a157190575.handle(Unknown Source)
> >>                 at
> org.apache.tapestry5.upload.internal.services.UploadExceptionFilter.handle(UploadExceptionFilter.java:76)
> >>                 at
> $ComponentEventRequestHandler_4a157190575.handle(Unknown Source)
> >>                 at
> org.apache.tapestry5.modules.TapestryModule$37.handle(TapestryModule.java:2216)
> >>                 at
> $ComponentEventRequestHandler_4a157190575.handle(Unknown Source)
> >>                 at
> $ComponentEventRequestHandler_4a157190441.handle(Unknown Source)
> >>                 at
> org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
> >>                 at
> org.apache.tapestry5.internal.services.DeferredResponseRenderer.handleComponentEvent(DeferredResponseRenderer.java:45)
> >>                 at
> $ComponentRequestHandler_4a157190443.handleComponentEvent(Unknown Source)
> >>                 at
> org.apache.tapestry5.services.InitializeActivePageName.handleComponentEvent(InitializeActivePageName.java:39)
> >>                 at
> $ComponentRequestHandler_4a157190443.handleComponentEvent(Unknown Source)
> >>                 at
> org.apache.tapestry5.internal.services.RequestOperationTracker$1.perform(RequestOperationTracker.java:55)
> >>                 at
> org.apache.tapestry5.internal.services.RequestOperationTracker$1.perform(RequestOperationTracker.java:52)
> >>                 at
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.perform(OperationTrackerImpl.java:110)
> >>                 at
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.perform(PerThreadOperationTracker.java:84)
> >>                 at
> org.apache.tapestry5.ioc.internal.RegistryImpl.perform(RegistryImpl.java:1266)
> >>                 at
> org.apache.tapestry5.internal.services.RequestOperationTracker.handleComponentEvent(RequestOperationTracker.java:47)
> >>                 at
> >> $ComponentRequestHandler_4a157190443.handleComponentEvent(Unknown
> Source) ....
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> > For additional commands, e-mail: users-h...@tapestry.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to