Re: correct way to call necessary javascript initialization when a component is added via ajax

2009-11-11 Thread svenmeier

Why so complicated?

@Override
public void renderHead(IHeaderResponse response) {
response.renderOnDomReadyJavascript(init_slider_js());
} 


Peter Ross-6 wrote:
 
 On Wed, Nov 11, 2009 at 3:48 PM, Jeremy Thomerson
 jer...@wickettraining.com wrote:
 On Tue, Nov 10, 2009 at 10:38 PM, Peter Ross
 p...@missioncriticalit.comwrote:

 Hi,

 I'm implementing a control which consists of an integer field and a
 slider where the slider comes from jquery UI.

 My question is that whenever the component is refreshed via ajax, you
 need to call the js initialization function.

 I've done this by adding a behaviour which determines the request
 target, if it's an AjaxRequestTarget it adds the init js to the target
 otherwise it outputs it in the header.

 Is this the correct way to do it?  Is there a simpler way?

 Yes - this looks fine.  There are multiple ways of accomplishing it, but
 this one is fine.

 Could you elaborate on what some of the other ways are?
 
 Just enough key words so that I can do the google search would be fine :)
 
 Peter
 
 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 

-- 
View this message in context: 
http://old.nabble.com/correct-way-to-call-necessary-javascript-initialization-when-a--component-is-added-via-ajax-tp26295973p26297483.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Re: correct way to call necessary javascript initialization when a component is added via ajax

2009-11-11 Thread Jeremy Thomerson
Won't work on an ajax request because the dom ready event isn't fired.
Right?

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



On Wed, Nov 11, 2009 at 2:23 AM, svenmeier s...@meiers.net wrote:


 Why so complicated?

 @Override
 public void renderHead(IHeaderResponse response) {
 response.renderOnDomReadyJavascript(init_slider_js());
 }


 Peter Ross-6 wrote:
 
  On Wed, Nov 11, 2009 at 3:48 PM, Jeremy Thomerson
  jer...@wickettraining.com wrote:
  On Tue, Nov 10, 2009 at 10:38 PM, Peter Ross
  p...@missioncriticalit.comwrote:
 
  Hi,
 
  I'm implementing a control which consists of an integer field and a
  slider where the slider comes from jquery UI.
 
  My question is that whenever the component is refreshed via ajax, you
  need to call the js initialization function.
 
  I've done this by adding a behaviour which determines the request
  target, if it's an AjaxRequestTarget it adds the init js to the target
  otherwise it outputs it in the header.
 
  Is this the correct way to do it?  Is there a simpler way?
 
  Yes - this looks fine.  There are multiple ways of accomplishing it, but
  this one is fine.
 
  Could you elaborate on what some of the other ways are?
 
  Just enough key words so that I can do the google search would be fine :)
 
  Peter
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 

 --
 View this message in context:
 http://old.nabble.com/correct-way-to-call-necessary-javascript-initialization-when-a--component-is-added-via-ajax-tp26295973p26297483.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


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




Re: correct way to call necessary javascript initialization when a component is added via ajax

2009-11-11 Thread mbrictson

Actually wicket-ajax.js is smart enough to fire these dom ready events
after an ajax request.

Of course, a jQuery $(document).ready() will not fire; neither will the
ready events of other various JS libraries. However if you specifically
use Wicket's dom ready event (i.e. renderOnDomReadyJavascript() as in the
Java example below, or manually in JavaScript using
Wicket.Event.addDomReadyEvent()), then the event will fire after the ajax
call.


jthomerson wrote:
 
 Won't work on an ajax request because the dom ready event isn't fired.
 Right?
 
 --
 Jeremy Thomerson
 http://www.wickettraining.com
 
 
 
 On Wed, Nov 11, 2009 at 2:23 AM, svenmeier s...@meiers.net wrote:
 

 Why so complicated?

 @Override
 public void renderHead(IHeaderResponse response) {
 response.renderOnDomReadyJavascript(init_slider_js());
 }

 
 

-- 
View this message in context: 
http://old.nabble.com/correct-way-to-call-necessary-javascript-initialization-when-a--component-is-added-via-ajax-tp26295973p26307595.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Re: correct way to call necessary javascript initialization when a component is added via ajax

2009-11-11 Thread Sven Meier

Right?


Wrong, see explanation below.

Sven

mbrictson wrote:

Actually wicket-ajax.js is smart enough to fire these dom ready events
after an ajax request.

Of course, a jQuery $(document).ready() will not fire; neither will the
ready events of other various JS libraries. However if you specifically
use Wicket's dom ready event (i.e. renderOnDomReadyJavascript() as in the
Java example below, or manually in JavaScript using
Wicket.Event.addDomReadyEvent()), then the event will fire after the ajax
call.


jthomerson wrote:
  

Won't work on an ajax request because the dom ready event isn't fired.
Right?

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



On Wed, Nov 11, 2009 at 2:23 AM, svenmeier s...@meiers.net wrote:



Why so complicated?

@Override
public void renderHead(IHeaderResponse response) {
response.renderOnDomReadyJavascript(init_slider_js());
}

  



  



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



Re: correct way to call necessary javascript initialization when a component is added via ajax

2009-11-11 Thread Peter Ross
On Wed, Nov 11, 2009 at 7:23 PM, svenmeier wrote:

 Why so complicated?

because I started by looking at what wiquery did and then simplifying
it to my case.  However I wasn't sure if it was the correct approach
or the most simple hence the question is there a better solution.

 @Override
 public void renderHead(IHeaderResponse response) {
    response.renderOnDomReadyJavascript(init_slider_js());
 }

This works great and is much simpler, thanks for the help.

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



correct way to call necessary javascript initialization when a component is added via ajax

2009-11-10 Thread Peter Ross
Hi,

I'm implementing a control which consists of an integer field and a
slider where the slider comes from jquery UI.

My question is that whenever the component is refreshed via ajax, you
need to call the js initialization function.

I've done this by adding a behaviour which determines the request
target, if it's an AjaxRequestTarget it adds the init js to the target
otherwise it outputs it in the header.

Is this the correct way to do it?  Is there a simpler way?

Here is the code that I've implemented as of today

public class NumberFieldWithSliderNumber extends FormComponentPanelNumber {
private TextFieldNumber field;
private String slider_id;

public NumberFieldWithSlider(String id) {
super(id);
init();
}

public NumberFieldWithSlider(String id, IModelNumber model) {
super(id, model);
init();
}

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() + });;
}
}

Regards,
Peter

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



Re: correct way to call necessary javascript initialization when a component is added via ajax

2009-11-10 Thread Jeremy Thomerson
Yes - this looks fine.  There are multiple ways of accomplishing it, but
this one is fine.

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



On Tue, Nov 10, 2009 at 10:38 PM, Peter Ross p...@missioncriticalit.comwrote:

 Hi,

 I'm implementing a control which consists of an integer field and a
 slider where the slider comes from jquery UI.

 My question is that whenever the component is refreshed via ajax, you
 need to call the js initialization function.

 I've done this by adding a behaviour which determines the request
 target, if it's an AjaxRequestTarget it adds the init js to the target
 otherwise it outputs it in the header.

 Is this the correct way to do it?  Is there a simpler way?

 Here is the code that I've implemented as of today

 public class NumberFieldWithSliderNumber extends
 FormComponentPanelNumber {
private TextFieldNumber field;
private String slider_id;

public NumberFieldWithSlider(String id) {
super(id);
init();
}

public NumberFieldWithSlider(String id, IModelNumber model) {
super(id, model);
init();
}

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() + });;
}
 }

 Regards,
 Peter

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




Re: correct way to call necessary javascript initialization when a component is added via ajax

2009-11-10 Thread Peter Ross
On Wed, Nov 11, 2009 at 3:48 PM, Jeremy Thomerson
jer...@wickettraining.com wrote:
 On Tue, Nov 10, 2009 at 10:38 PM, Peter Ross 
 p...@missioncriticalit.comwrote:

 Hi,

 I'm implementing a control which consists of an integer field and a
 slider where the slider comes from jquery UI.

 My question is that whenever the component is refreshed via ajax, you
 need to call the js initialization function.

 I've done this by adding a behaviour which determines the request
 target, if it's an AjaxRequestTarget it adds the init js to the target
 otherwise it outputs it in the header.

 Is this the correct way to do it?  Is there a simpler way?

 Yes - this looks fine.  There are multiple ways of accomplishing it, but
 this one is fine.

Could you elaborate on what some of the other ways are?

Just enough key words so that I can do the google search would be fine :)

Peter

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