Ok, try this
add( new AbstractBehavior() {
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.renderJavascript("<some dynamically
generated JS>", "<uniqueID>");
}
}
);
Every time the component (to that the AbstractBehaivor is added) is redrawn
(eg. Initally or after an AjaxUpodate) the dynamically generated javascript is
renderedinto <HEAD>.
If you want to make sure that it is not rendered twice from another component
with thie AbstractBehavior, just add some "uniqueID" in the renderJavascript
call.
-----Ursprüngliche Nachricht-----
Von: Sigmar Muuga [mailto:[email protected]]
Gesendet: Sonntag, 21. März 2010 21:22
An: [email protected]
Betreff: Re: Dynamic javascript generation
I need to include this dynamic js in my header with <script> tag like this
in gmail:
<script src="?view=page&name=browser&ver=zpwhtygjntrz
<view-source:https://mail.google.com/mail/?view=page&name=browser&ver=zpwhtygjntrz>"></script>
Some behaviour of that script depends on my session data on server side.
I think that its not very complicated
But I dont want to hardcode it to my html page, because urls and paths my
changes. Dealing with resources provides more reliable configuration etc..
Sigmar
On Sun, Mar 21, 2010 at 9:19 PM, Stefan Lindner <[email protected]> wrote:
> Generate some Javasript in response to e.g. a button klick?
> Or generate JavaScript when the page is rendered?
>
> -----Ursprüngliche Nachricht-----
> Von: Sigmar Muuga [mailto:[email protected]]
> Gesendet: Sonntag, 21. März 2010 19:53
> An: [email protected]
> Betreff: Dynamic javascript generation
>
> Hello,
> I have to generate some javascript on the server side and then include it
> into my page.
> Which is the best way to do this with current stable wicket release?
>
> A the moment I am thinking about extending WebResource....
>
> Sigmar
>