How to add Javascript function in wicket 1.4 Page

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

How to add Javascript function in wicket 1.4 Page

raju.ch
Hi,
 I want to add Javascript which loads Javascript client side variables when a page loads. It would call a Javascript function and pass in server-side values.I want to add something like this

<script> var val = 123; </script>
Please note that it is not part of the header. Any help would greatly appreciable.
Reply | Threaded
Open this post in threaded view
|

Re: How to add Javascript function in wicket 1.4 Page

Dan Retzlaff
Hi, Raju. See if adding this to your Wicket component's constructor does
what you want:

add(new HeaderContributor(new IHeaderContributor() {
@Override
public void renderHead(IHeaderResponse response) {
response.renderOnDomReadyJavascript("alert('ready')");
}
}));

On Wed, Dec 7, 2011 at 8:25 PM, raju.ch <[hidden email]> wrote:

> Hi,
>  I want to add Javascript which loads Javascript client side variables when
> a page loads. It would call a Javascript function and pass in server-side
> values.I want to add something like this
>
>
>
> Please note that it is not part of the header. Any help would greatly
> appreciable.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-add-Javascript-function-in-wicket-1-4-Page-tp4171520p4171520.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to add Javascript function in wicket 1.4 Page

raju.ch
Hi Dan,
Thank you for your reply, I had resolved it by writing the below code
get("body").add(new AjaxEventBehavior("onload") {
                        /**
                                         *
                                         */
                        private static final long serialVersionUID = 5189233126299039152L;

                        protected void onEvent(AjaxRequestTarget target) {

                                target
                                                .appendJavascript("alert(123)");
}