You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by adrienleroy <ad...@gmail.com> on 2008/10/28 20:46:25 UTC

AbstractDefaultAjaxBehavior in a panel not working when loaded from an ajax context

Hello,

I am trying to implements this JavaScript timedatepicker
http://labs.perifer.se/timedatepicker/ as an AbstractDefaultAjaxBehavior
here my class

public class TimePickBehavior extends AbstractDefaultAjaxBehavior {

    private static final CompressedResourceReference TIMEPICKER_JS = new
CompressedResourceReference(
            TimePickBehavior.class, "resource/jquery.timePicker.js");
    private static final CompressedResourceReference TIMEPICKER_CSS = new
CompressedResourceReference(
            TimePickBehavior.class, "resource/timePicker.css");
    private String startHourMarkupId;
    private String endHourMarkupId;

    public TimePickBehavior(String startHourMarkupId, String
endHourMarkupId) {
        this.startHourMarkupId = startHourMarkupId;
        this.endHourMarkupId = endHourMarkupId;
    }

    @Override
    public void renderHead(IHeaderResponse response) {
        super.renderHead(response);
        response.renderCSSReference(TIMEPICKER_CSS);
        response.renderJavascriptReference(TIMEPICKER_JS);
        String timePickerJS = "jQuery(function() {";
        timePickerJS += "$(\"#" + startHourMarkupId + ",#" + endHourMarkupId
+ "\").timePicker();";
        timePickerJS += "var oldTime = $.timePicker(\"#" + startHourMarkupId
+ "\").getTime();";
        timePickerJS += "$(\"#" + startHourMarkupId + "\").change(function()
{";
        timePickerJS += "if ($(\"#" + endHourMarkupId + "\").val()) {";
        timePickerJS += "var duration = ($.timePicker(\"#" + endHourMarkupId
+ "\").getTime() - oldTime);";
        timePickerJS += "var time = $.timePicker(\"#" + startHourMarkupId +
"\").getTime();";
        timePickerJS += "$.timePicker(\"#" + endHourMarkupId +
"\").setTime(new Date(new Date(time.getTime() + duration)));";
        timePickerJS += "oldTime = time;";
        timePickerJS += "}";
        timePickerJS += "});";
        timePickerJS += "$(\"#" + endHourMarkupId + "\").change(function()
{";
        timePickerJS += "if($.timePicker(\"#" + startHourMarkupId +
"\").getTime() > $.timePicker(this).getTime()) {";
        timePickerJS += "$(this).addClass(\"error\");";
        timePickerJS += "}";
        timePickerJS += "else {";
        timePickerJS += "$(this).removeClass(\"error\");}});});";
        //timePickerJS += "//fin du script";
        response.renderJavascript(timePickerJS,null);
    }

    @Override
    protected void respond(AjaxRequestTarget arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

I have a page where i call a panel in ajax with this behaviour in it. In
that case the JavaScript is not working. But if i refresh the page it is
working.
In debug mode the JavaScript generated by this behaviour is between the
<header-contribution encoding="wicket1" > mark-up of the response. But it
seems unevaluated.

It seems to works in a none ajax context only.

I have tried different things to find where the problem is, but i am out of
ideas.

Thanks for any help


-- 
View this message in context: http://www.nabble.com/AbstractDefaultAjaxBehavior-in-a-panel-not-working-when-loaded-from-an-ajax-context-tp20214617p20214617.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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