You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Muro Copenhagen <co...@gmail.com> on 2010/06/29 16:45:16 UTC

Re-rendering javascript in behavior

Hi,

I have a small behavior that prevents doubleclick on buttons.

It is added to Modal popups on a page. The problem i have is that if the
Modal window appears twice on a page,
the javascript variable value of the first popup is used.

This is because i am using: response.renderJavascript(...); which is only
rendered once.

How can i force rerendering of the javascript, or is there any other way of
achieving defaulting the javascript variable,
for each modal window on my page?


This is how it my behavior looks:

public class PreventDoubleClickBehavior extends AbstractBehavior {

    private String submitScript = "if(submitting) {this.disabled = true;
return false;} else {submitting = true;}";

    @Override
    public void renderHead(IHeaderResponse response) {
        response.renderJavascript("var submitting = false;", "pdcJS");
    }

    @Override
    public void onComponentTag(Component component, ComponentTag tag) {
        IValueMap valueMap = tag.getAttributes();
        CharSequence oldOnclickFunctions =
valueMap.getCharSequence("onclick");
        if (oldOnclickFunctions == null) {
            oldOnclickFunctions = "";
        }
        tag.put("onclick", submitScript + oldOnclickFunctions);
    }
}

Thanks in advance...

Muro

Re: Re-rendering javascript in behavior

Posted by Jeremy Thomerson <je...@wickettraining.com>.
Of course, you'll still have the issue that you are using a single global
variable for multiple things on the page.

On Tue, Jun 29, 2010 at 10:24 AM, Igor Vaynberg <ig...@gmail.com>wrote:

> the javascript contributions are filtered by the id given in the
> second parameter, in your case:  "pdcJS". since your ids are constant
> only the first contribution makes it.
>
> using UUID.random() will fix it it as far as header contributions go.
>
> -igor
>
> On Tue, Jun 29, 2010 at 7:45 AM, Muro Copenhagen <co...@gmail.com>
> wrote:
> > Hi,
> >
> > I have a small behavior that prevents doubleclick on buttons.
> >
> > It is added to Modal popups on a page. The problem i have is that if the
> > Modal window appears twice on a page,
> > the javascript variable value of the first popup is used.
> >
> > This is because i am using: response.renderJavascript(...); which is only
> > rendered once.
> >
> > How can i force rerendering of the javascript, or is there any other way
> of
> > achieving defaulting the javascript variable,
> > for each modal window on my page?
> >
> >
> > This is how it my behavior looks:
> >
> > public class PreventDoubleClickBehavior extends AbstractBehavior {
> >
> >    private String submitScript = "if(submitting) {this.disabled = true;
> > return false;} else {submitting = true;}";
> >
> >    @Override
> >    public void renderHead(IHeaderResponse response) {
> >        response.renderJavascript("var submitting = false;", "pdcJS");
> >    }
> >
> >    @Override
> >    public void onComponentTag(Component component, ComponentTag tag) {
> >        IValueMap valueMap = tag.getAttributes();
> >        CharSequence oldOnclickFunctions =
> > valueMap.getCharSequence("onclick");
> >        if (oldOnclickFunctions == null) {
> >            oldOnclickFunctions = "";
> >        }
> >        tag.put("onclick", submitScript + oldOnclickFunctions);
> >    }
> > }
> >
> > Thanks in advance...
> >
> > Muro
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Jeremy Thomerson
http://www.wickettraining.com

Re: Re-rendering javascript in behavior

Posted by Igor Vaynberg <ig...@gmail.com>.
the javascript contributions are filtered by the id given in the
second parameter, in your case:  "pdcJS". since your ids are constant
only the first contribution makes it.

using UUID.random() will fix it it as far as header contributions go.

-igor

On Tue, Jun 29, 2010 at 7:45 AM, Muro Copenhagen <co...@gmail.com> wrote:
> Hi,
>
> I have a small behavior that prevents doubleclick on buttons.
>
> It is added to Modal popups on a page. The problem i have is that if the
> Modal window appears twice on a page,
> the javascript variable value of the first popup is used.
>
> This is because i am using: response.renderJavascript(...); which is only
> rendered once.
>
> How can i force rerendering of the javascript, or is there any other way of
> achieving defaulting the javascript variable,
> for each modal window on my page?
>
>
> This is how it my behavior looks:
>
> public class PreventDoubleClickBehavior extends AbstractBehavior {
>
>    private String submitScript = "if(submitting) {this.disabled = true;
> return false;} else {submitting = true;}";
>
>    @Override
>    public void renderHead(IHeaderResponse response) {
>        response.renderJavascript("var submitting = false;", "pdcJS");
>    }
>
>    @Override
>    public void onComponentTag(Component component, ComponentTag tag) {
>        IValueMap valueMap = tag.getAttributes();
>        CharSequence oldOnclickFunctions =
> valueMap.getCharSequence("onclick");
>        if (oldOnclickFunctions == null) {
>            oldOnclickFunctions = "";
>        }
>        tag.put("onclick", submitScript + oldOnclickFunctions);
>    }
> }
>
> Thanks in advance...
>
> Muro
>

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