Why can't you just render the javascript in renderHead?
-Matej
On Tue, Jul 22, 2008 at 1:28 PM, Martijn Dashorst
<[EMAIL PROTECTED]> wrote:
> the usecase: in onbeforerender we want to add some prepended
> javascript to the ajaxrequesttarget, sort of like:
>
> public class HomePage extends WebPage {
> private static final long serialVersionUID = 1L;
> private int teller = 0;
> public int getTeller() { return teller++; }
>
> public HomePage(final PageParameters parameters) {
> add(new Label("message",
> new PropertyModel(this, "teller")) {
>
> protected void onBeforeRender() {
> super.onBeforeRender();
> if (getRequestCycle().getRequestTarget()
> instanceof AjaxRequestTarget) {
> ((AjaxRequestTarget)
> getRequestCycle().getRequestTarget())
>
> .prependJavascript("alert('foo');");
> }
> }
> }.setOutputMarkupId(true));
>
> add(new AjaxLink("foo") {
> public void onClick(AjaxRequestTarget target) {
>
> target.addComponent(HomePage.this.get("message"));
> }
> });
> }
> }
>
> But this obviously doesn't work, since onbeforerender is called after
> the prepended javascripts are added to the ajax request target. There
> are some ways to solve this conundrum:
>
> 1. do the before render cycle before prepend javascripts, prepend
> javascript, render, append javascript
> 2. render to temporary string, prepend javascript, append javascript,
> concatenate in correct order
> 3. adjust wicket-ajax.js / communication protocal to 'type' the
> various elements, and let wicket-ajax first call prepend, replace
> component, append javascript.
>
> Any other ideas?
>
> Martijn
>