Hi Esteban, the wicket javascript will update your component html by the on
retrieved by your component that has the script tag attached. So you get the
problem describe. If you want to keep sending the java script by script tag,
you can implement your onComponentRendered method like:

if (AjaxRequestTarget.get() != null){
  AjaxRequestTarget.get().appendJavascript("var foo = new
Wicket.ExtensibleChoiceAutocomplete ...");
} else {
  cResponse.write(JavascriptUtils.SCRIPT_OPEN_TAG);
  cResponse.write("var foo = new Wicket.ExtensibleChoiceAutocomplete ...");
  cResponse.write(JavascriptUtils.SCRIPT_CLOSE_TAG);
}

but the best approach is to send your behavior javascript to browser adding
it to the IHeaderResponse like:

response.renderOnDomReadyJavascript("var foo = new
Wicket.ExtensibleChoiceAutocomplete ...");

you can do it overriding the renderHead method, because AbstractBehavior
implements IHeaderContributor

On Wed, Jan 13, 2010 at 5:34 PM, Esteban Masoero
<[email protected]>wrote:

> Hi:
>
> Using wicket 1.3.5, I have a MyAbstractExtensibleChoiceAutocompleteBehavior
> (that extends AbstractDefaultAjaxBehavior, and I think it is a modification
> of some wicket class) related to the autocomplete feature that inside
> onComponentRendered method does something like:
>
> cResponse.write(JavascriptUtils.SCRIPT_OPEN_TAG);
> cResponse.write("var foo = new Wicket.ExtensibleChoiceAutocomplete ...");
> cResponse.write(JavascriptUtils.SCRIPT_CLOSE_TAG);
>
> Then I have a MyTextField subclass that adds this behavior to itself when
> it's constructed, so the "autocomplete" options are shown properly.
> MyTextField also adds to itself an
> AjaxFormComponentUpdatingBehavior("onchange") so we can track the changes
> and do some stuff.
>
> So here's the thing, I noticed with firebug that every time I change the
> component's value and the AjaxFormComponentUpdatingBehavior is called,
> MyTextField is refreshed (added to the target) and the onComponentRendered
> method of the other behavior is called, and the js tag is added to the one
> that previously existed. So I have:
>
> <script type="text/javascript".../</script>
> <script type="text/javascript".../</script>
>
> ...and everytime I change the component's value, one line is added. From
> what I saw in Wicket.ExtensibleChoiceAutocomplete class, It shouldn't have
> negative effects, however, I also think it's not a desired effect.
> Can anyone tell me if this is normal or I'm doing something wrong or
> whether I shouldn't worry at all?
>
> Thanks,
>
> Esteban
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Pedro Henrique Oliveira dos Santos

Reply via email to