You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris <ch...@gmx.at> on 2015/04/27 04:15:44 UTC

load JS after page refresh

Hi all,

how is it possible to load a JS function after a specific page refresh based on an ajax link click?

 Link link = new AjaxFallbackLink("link") {
            @Override
            public void onClick(AjaxRequestTarget target) {
                target.add(getPage());
            }
  };

Thanks, Chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: load JS after page refresh

Posted by kovaron <ko...@gmail.com>.
Hello,
On the arrival page you can do it in renderHead. Isn't it good for you?

chris.gr [via Apache Wicket] <ml...@n4.nabble.com>
ezt írta (időpont: 2015. ápr. 27., Hét 4:16):

> Hi all,
>
> how is it possible to load a JS function after a specific page refresh
> based on an ajax link click?
>
>  Link link = new AjaxFallbackLink("link") {
>             @Override
>             public void onClick(AjaxRequestTarget target) {
>                 target.add(getPage());
>             }
>   };
>
> Thanks, Chris
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4670509&i=0>
> For additional commands, e-mail: [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4670509&i=1>
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-wicket.1842946.n4.nabble.com/load-JS-after-page-refresh-tp4670509.html
>  To start a new topic under Users forum, email
> ml-node+s1842946n1842947h34@n4.nabble.com
> To unsubscribe from Users forum, click here
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1842947&code=a292YXJvbjFAZ21haWwuY29tfDE4NDI5NDd8MjY3OTE2NzY=>
> .
> NAML
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/load-JS-after-page-refresh-tp4670509p4670510.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: load JS after page refresh

Posted by Chris <ch...@gmx.at>.
Perfect, thanks  a lot!

Chris


> Am 27.04.2015 um 13:21 schrieb Sven Meier <sv...@meiers.net>:
> 
> Hi,
> 
> I've tried your sample project and identified the problem:
> 
> Since you're adding the whole page to the AjaxRequestTarget, Wicket will immediately issue a redirect to the current page.
> But at the end of the current request, the page is detached - this removes all temporary behaviors.
> 
> The page is then re-rendered after the redirect, but the behavior is no longer present to write any JavaScript to the header.
> 
> You could change your behavior to mark itself as temporary only *after* it has done its duty:
> 
>                    @Override
>                    public void renderHead(Component component, IHeaderResponse response) {
>                        super.renderHead(component, response);
> response.render(OnDomReadyHeaderItem.forScript("alert('test')"));
>                        alerted = true;
>                    }
> 
>                    @Override
>                    public boolean isTemporary(Component component) {
>                        return alerted;
>                    }
> 
> Regards
> Sven
> 
> 
> On 27.04.2015 12:10, Chris wrote:
>> I understand - I just made a quick start project with the code below that shows when setting isTemporary=true JS is not called.
>> https://github.com/cat1000/loadjs <https://github.com/cat1000/loadjs> <https://github.com/cat1000/loadjs <https://github.com/cat1000/loadjs>>
>> 
>> If anyone can point me to the error, it would be great.
>> 
>> Thanks, Chris
>> 
>>> Am 27.04.2015 um 10:59 schrieb Martin Grigorov <mg...@apache.org>:
>>> 
>>> I am not sure what problem you face but it should be 'true'.
>>> Otherwise the behavior remains attached to the page and any following
>>> re-renderings of the page will execute this JS code again.
>>> 
>>> Martin Grigorov
>>> Wicket Training and Consulting
>>> https://twitter.com/mtgrigorov
>>> 
>>> On Mon, Apr 27, 2015 at 11:52 AM, Chris <ch...@gmx.at> wrote:
>>> 
>>>> Hi all,
>>>> 
>>>> thanks Martin. I have to set isTemporary=false, otherwise the JS will not
>>>> be called.
>>>> 
>>>> 
>>>> public void onClick(AjaxRequestTarget target) {
>>>>                target.add(getPage().add(new Behavior() {
>>>>                    @Override
>>>>                    public void renderHead(Component component,
>>>> IHeaderResponse response) {
>>>>                        super.renderHead(component, response);
>>>> 
>>>> response.render(OnDomReadyHeaderItem.forScript("call..."));
>>>>                    }
>>>> 
>>>>                    @Override
>>>>                    public boolean isTemporary(Component component) {
>>>>                        return false;
>>>>                    }
>>>>                }));
>>>> 
>>>>  }
>>>> 
>>>> 
>>>> Chris
>>>> 
>>>>> Am 27.04.2015 um 08:49 schrieb Martin Grigorov <mg...@apache.org>:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> You can create a Behavior with #renderHead() to render the JS and
>>>>> #isTemporary() {return true} so that it is removed automatically after
>>>> the
>>>>> rendering.
>>>>> Add this Behavior in #onClick() to the page.
>>>>> 
>>>>> Martin Grigorov
>>>>> Wicket Training and Consulting
>>>>> https://twitter.com/mtgrigorov
>>>>> 
>>>>> On Mon, Apr 27, 2015 at 5:15 AM, Chris <ch...@gmx.at> wrote:
>>>>> 
>>>>>> Hi all,
>>>>>> 
>>>>>> how is it possible to load a JS function after a specific page refresh
>>>>>> based on an ajax link click?
>>>>>> 
>>>>>> Link link = new AjaxFallbackLink("link") {
>>>>>>           @Override
>>>>>>           public void onClick(AjaxRequestTarget target) {
>>>>>>               target.add(getPage());
>>>>>>           }
>>>>>> };
>>>>>> 
>>>>>> Thanks, Chris
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>> 
>>>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>> 
>>>> 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org <ma...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org <ma...@wicket.apache.org>

Re: load JS after page refresh

Posted by Sven Meier <sv...@meiers.net>.
Hi,

I've tried your sample project and identified the problem:

Since you're adding the whole page to the AjaxRequestTarget, Wicket will 
immediately issue a redirect to the current page.
But at the end of the current request, the page is detached - this 
removes all temporary behaviors.

The page is then re-rendered after the redirect, but the behavior is no 
longer present to write any JavaScript to the header.

You could change your behavior to mark itself as temporary only *after* 
it has done its duty:

                     @Override
                     public void renderHead(Component component, 
IHeaderResponse response) {
                         super.renderHead(component, response);
response.render(OnDomReadyHeaderItem.forScript("alert('test')"));
                         alerted = true;
                     }

                     @Override
                     public boolean isTemporary(Component component) {
                         return alerted;
                     }

Regards
Sven


On 27.04.2015 12:10, Chris wrote:
> I understand - I just made a quick start project with the code below that shows when setting isTemporary=true JS is not called.
> https://github.com/cat1000/loadjs <https://github.com/cat1000/loadjs>
>
> If anyone can point me to the error, it would be great.
>
> Thanks, Chris
>
>> Am 27.04.2015 um 10:59 schrieb Martin Grigorov <mg...@apache.org>:
>>
>> I am not sure what problem you face but it should be 'true'.
>> Otherwise the behavior remains attached to the page and any following
>> re-renderings of the page will execute this JS code again.
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>> https://twitter.com/mtgrigorov
>>
>> On Mon, Apr 27, 2015 at 11:52 AM, Chris <ch...@gmx.at> wrote:
>>
>>> Hi all,
>>>
>>> thanks Martin. I have to set isTemporary=false, otherwise the JS will not
>>> be called.
>>>
>>>
>>> public void onClick(AjaxRequestTarget target) {
>>>                 target.add(getPage().add(new Behavior() {
>>>                     @Override
>>>                     public void renderHead(Component component,
>>> IHeaderResponse response) {
>>>                         super.renderHead(component, response);
>>>
>>> response.render(OnDomReadyHeaderItem.forScript("call..."));
>>>                     }
>>>
>>>                     @Override
>>>                     public boolean isTemporary(Component component) {
>>>                         return false;
>>>                     }
>>>                 }));
>>>
>>>   }
>>>
>>>
>>> Chris
>>>
>>>> Am 27.04.2015 um 08:49 schrieb Martin Grigorov <mg...@apache.org>:
>>>>
>>>> Hi,
>>>>
>>>> You can create a Behavior with #renderHead() to render the JS and
>>>> #isTemporary() {return true} so that it is removed automatically after
>>> the
>>>> rendering.
>>>> Add this Behavior in #onClick() to the page.
>>>>
>>>> Martin Grigorov
>>>> Wicket Training and Consulting
>>>> https://twitter.com/mtgrigorov
>>>>
>>>> On Mon, Apr 27, 2015 at 5:15 AM, Chris <ch...@gmx.at> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> how is it possible to load a JS function after a specific page refresh
>>>>> based on an ajax link click?
>>>>>
>>>>> Link link = new AjaxFallbackLink("link") {
>>>>>            @Override
>>>>>            public void onClick(AjaxRequestTarget target) {
>>>>>                target.add(getPage());
>>>>>            }
>>>>> };
>>>>>
>>>>> Thanks, Chris
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: load JS after page refresh

Posted by Chris <ch...@gmx.at>.
I understand - I just made a quick start project with the code below that shows when setting isTemporary=true JS is not called.
https://github.com/cat1000/loadjs <https://github.com/cat1000/loadjs>

If anyone can point me to the error, it would be great.

Thanks, Chris

> Am 27.04.2015 um 10:59 schrieb Martin Grigorov <mg...@apache.org>:
> 
> I am not sure what problem you face but it should be 'true'.
> Otherwise the behavior remains attached to the page and any following
> re-renderings of the page will execute this JS code again.
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Mon, Apr 27, 2015 at 11:52 AM, Chris <ch...@gmx.at> wrote:
> 
>> Hi all,
>> 
>> thanks Martin. I have to set isTemporary=false, otherwise the JS will not
>> be called.
>> 
>> 
>> public void onClick(AjaxRequestTarget target) {
>>                target.add(getPage().add(new Behavior() {
>>                    @Override
>>                    public void renderHead(Component component,
>> IHeaderResponse response) {
>>                        super.renderHead(component, response);
>> 
>> response.render(OnDomReadyHeaderItem.forScript("call..."));
>>                    }
>> 
>>                    @Override
>>                    public boolean isTemporary(Component component) {
>>                        return false;
>>                    }
>>                }));
>> 
>>  }
>> 
>> 
>> Chris
>> 
>>> Am 27.04.2015 um 08:49 schrieb Martin Grigorov <mg...@apache.org>:
>>> 
>>> Hi,
>>> 
>>> You can create a Behavior with #renderHead() to render the JS and
>>> #isTemporary() {return true} so that it is removed automatically after
>> the
>>> rendering.
>>> Add this Behavior in #onClick() to the page.
>>> 
>>> Martin Grigorov
>>> Wicket Training and Consulting
>>> https://twitter.com/mtgrigorov
>>> 
>>> On Mon, Apr 27, 2015 at 5:15 AM, Chris <ch...@gmx.at> wrote:
>>> 
>>>> Hi all,
>>>> 
>>>> how is it possible to load a JS function after a specific page refresh
>>>> based on an ajax link click?
>>>> 
>>>> Link link = new AjaxFallbackLink("link") {
>>>>           @Override
>>>>           public void onClick(AjaxRequestTarget target) {
>>>>               target.add(getPage());
>>>>           }
>>>> };
>>>> 
>>>> Thanks, Chris
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>> 
>>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 


Re: load JS after page refresh

Posted by Martin Grigorov <mg...@apache.org>.
I am not sure what problem you face but it should be 'true'.
Otherwise the behavior remains attached to the page and any following
re-renderings of the page will execute this JS code again.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Mon, Apr 27, 2015 at 11:52 AM, Chris <ch...@gmx.at> wrote:

> Hi all,
>
> thanks Martin. I have to set isTemporary=false, otherwise the JS will not
> be called.
>
>
>  public void onClick(AjaxRequestTarget target) {
>                 target.add(getPage().add(new Behavior() {
>                     @Override
>                     public void renderHead(Component component,
> IHeaderResponse response) {
>                         super.renderHead(component, response);
>
> response.render(OnDomReadyHeaderItem.forScript("call..."));
>                     }
>
>                     @Override
>                     public boolean isTemporary(Component component) {
>                         return false;
>                     }
>                 }));
>
>   }
>
>
> Chris
>
> > Am 27.04.2015 um 08:49 schrieb Martin Grigorov <mg...@apache.org>:
> >
> > Hi,
> >
> > You can create a Behavior with #renderHead() to render the JS and
> > #isTemporary() {return true} so that it is removed automatically after
> the
> > rendering.
> > Add this Behavior in #onClick() to the page.
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Mon, Apr 27, 2015 at 5:15 AM, Chris <ch...@gmx.at> wrote:
> >
> >> Hi all,
> >>
> >> how is it possible to load a JS function after a specific page refresh
> >> based on an ajax link click?
> >>
> >> Link link = new AjaxFallbackLink("link") {
> >>            @Override
> >>            public void onClick(AjaxRequestTarget target) {
> >>                target.add(getPage());
> >>            }
> >>  };
> >>
> >> Thanks, Chris
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: load JS after page refresh

Posted by Chris <ch...@gmx.at>.
Hi all,

thanks Martin. I have to set isTemporary=false, otherwise the JS will not be called.


 public void onClick(AjaxRequestTarget target) {
                target.add(getPage().add(new Behavior() {
                    @Override
                    public void renderHead(Component component, IHeaderResponse response) {
                        super.renderHead(component, response);
                        response.render(OnDomReadyHeaderItem.forScript("call..."));
                    }

                    @Override
                    public boolean isTemporary(Component component) {
                        return false;
                    }
                }));

  }


Chris

> Am 27.04.2015 um 08:49 schrieb Martin Grigorov <mg...@apache.org>:
> 
> Hi,
> 
> You can create a Behavior with #renderHead() to render the JS and
> #isTemporary() {return true} so that it is removed automatically after the
> rendering.
> Add this Behavior in #onClick() to the page.
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Mon, Apr 27, 2015 at 5:15 AM, Chris <ch...@gmx.at> wrote:
> 
>> Hi all,
>> 
>> how is it possible to load a JS function after a specific page refresh
>> based on an ajax link click?
>> 
>> Link link = new AjaxFallbackLink("link") {
>>            @Override
>>            public void onClick(AjaxRequestTarget target) {
>>                target.add(getPage());
>>            }
>>  };
>> 
>> Thanks, Chris
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: load JS after page refresh

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

You can create a Behavior with #renderHead() to render the JS and
#isTemporary() {return true} so that it is removed automatically after the
rendering.
Add this Behavior in #onClick() to the page.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Mon, Apr 27, 2015 at 5:15 AM, Chris <ch...@gmx.at> wrote:

> Hi all,
>
> how is it possible to load a JS function after a specific page refresh
> based on an ajax link click?
>
>  Link link = new AjaxFallbackLink("link") {
>             @Override
>             public void onClick(AjaxRequestTarget target) {
>                 target.add(getPage());
>             }
>   };
>
> Thanks, Chris
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>