Re: correct way to call necessary javascript initialization when a component is added via ajax
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
Re: Wicket and JQuery
On Wed, Nov 11, 2009 at 3:53 PM, Peter Ross pdr...@gmail.com wrote: 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); } } }); } Someone helpfully pointed out to me that renderHead could be simplified to 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
correct way to call necessary javascript initialization when a component is added via ajax
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
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
Re: Wicket and JQuery
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
Request to improve documentation of onRuntimeException
Hi, I'm looking at overriding onRuntimeException[1]to do some cleanup if there was an exception,however I want the standard error handling page to be displayed. I thought I would need use getInternalErrorPage and then do some tricky stuff to instantiate it, but after inspecting AbstractRequestCycleProcessor then it appears that just returning null is sufficient to get the standard wicket error handling page. It would be nice if the documentation stated that returning null will leave it up to the RequestCycleProcessor to display what page to display, and that the standard wicket RequestCycleProcessor will simply display the default error page in this case. Regards Pete [1] http://wicket.apache.org/docs/1.4/org/apache/wicket/RequestCycle.html#onRuntimeException(org.apache.wicket.Page,%20java.lang.RuntimeException) - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Using Prince XML to generate PDF of wicket page
On Mon, Apr 6, 2009 at 12:18 PM, Peter Ross pdr...@gmail.com wrote: Hi, I'm new to wicket and I am looking at integrating Prince XML with Wicket. Prince supplies a method public boolean convert(InputStream xmlInput, OutputStream pdfOutput) throws IOException What I would like to do is add this into the rendering pipeline for a page, so that I can get the HTML of the page as a stream and then return the page as a PDF. I've explored the mailing list and examples and the closest example I can find is for sending an email at http://www.wicket-library.com/wicket-examples/staticpages/ and I was wondering is this the correct approach, or should I be looking at something else? I ended up pretty much following the code from the static pages example, except I use requestCycle.setRedirect(false) rather than using mount and having a special BookmarkablePageRequestTargetUrlCodingStrategy. As far as I can tell the only problem with doing it my way is the double submit problem. However as long as the page I render doesn't do any state updates then this is not a problem because all that will happen is that I will get the file being generated twice on the server. Here is the code that I'm using: public class PdfPageRequestTarget extends BookmarkablePageRequestTarget { private String filename; public PdfPageRequestTarget(java.lang.Class PageClass, String filename) { super(PageClass); this.filename = filename; } @Override public void respond(RequestCycle requestCycle) { // In the staticpages example of wicket there is the following comment: // Unfortunately, you cannot use // CapturingBookmarkablePageRequestTarget in an event listener // like onClick() unless you change the application's // IRequestCycleSettings to ONE_PASS_RENDER // // Thus we setRedirect to be false, meaning that ONE_PASS_RENDER is // enabled for just this request. If you don't then s.ToString() // returns the empty string. requestCycle.setRedirect(false); // Save the web response we are rendering into WebResponse w = (WebResponse) requestCycle.get().getResponse(); // Render into a string StringResponse s = new StringResponse(); requestCycle.get().setResponse(s); super.respond(requestCycle); // Restore the web response RequestCycle.get().setResponse(w); // Now set up a text file which contains the requested pages html. ResourceStreamRequestTarget target = new ResourceStreamRequestTarget(new StringResourceStream(s.toString(), text/plain)); target.setFileName(this.filename); // Now request that the result of rendering be the text file. requestCycle.get().setRequestTarget(target); } } - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Using Prince XML to generate PDF of wicket page
Hi, I'm new to wicket and I am looking at integrating Prince XML with Wicket. Prince supplies a method public boolean convert(InputStream xmlInput, OutputStream pdfOutput) throws IOException What I would like to do is add this into the rendering pipeline for a page, so that I can get the HTML of the page as a stream and then return the page as a PDF. I've explored the mailing list and examples and the closest example I can find is for sending an email at http://www.wicket-library.com/wicket-examples/staticpages/ and I was wondering is this the correct approach, or should I be looking at something else? Thanks, Pete - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org