On Wed, Oct 28, 2009 at 5:08 PM, Jason Novotny  wrote:
> Martin Makundi wrote:
>>
>> ... and expect trouble with ajaxifying jquery plugins that skin html
>> components. They will not work properly if you replace your components
>> via ajax - or at least you might have to work hard on it.
>>
>
>   Bingo!! I've been hitting this wall, and pulling my hair out-- in fact I
> may ditch jQuery for this very reason since I can't find a suitable
> workaround :-(
>
Here is the solution I used, I just emailed the list to ask if this is
the correct approach:

The following is some code which has an integer field with an associated slider

The AbstractBehavior is the bit which determines if we are in an ajax
request or not and adds the init js code in the correct place to make
sure it's called.
    private void init() {
        field = new TextField("field", getModel());
        add(field);

        WebComponent c = new WebComponent("slider");
        c.setOutputMarkupId(true);
        slider_id = c.getMarkupId();
        add(c);

        // Write out the javascript to initialize the slider
        add(new AbstractBehavior() {
            @Override
            public void renderHead(IHeaderResponse response) {
                IRequestTarget target = RequestCycle.get().getRequestTarget();

                if (target instanceof AjaxRequestTarget) {
                    // If the target is an ajax request then we need
                    // to execute just the slider js.
                    AjaxRequestTarget t = (AjaxRequestTarget) target;
                    t.appendJavascript(init_slider_js());
                } else {
                    // Otherwise render the slider when the document is ready.

response.renderJavascript(init_slider_when_doc_ready_js(), null);
                }
            }
        });

    }

    private String init_slider_js() {
        return "$('#" + slider_id + "').slider({min: 0, max: 1, step: 0.1});";
    }

    private String init_slider_when_doc_ready_js() {
        return "$(document).ready(function() {" + init_slider_js() + "});";
    }

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

Reply via email to