Hi,

The demo app for "what's new in Wicket 6's JavaScript" does exactly this:
http://wicketinaction.com/2012/07/wicket-6-javascript-improvements/


On Wed, Feb 27, 2013 at 6:34 AM, Paul Bors <p...@bors.ws> wrote:

> If you want to see a simple project using Jackson to render JSON on the
> page take a look at:
> http://wicket-continuous-calendar.GoogleCode.com/
>
> Or a bit bigger one:
> http://wicked-charts.GoogleCode.com
>
> Or poke around other open source code projects in Wicket that use those
> dependencies in Maven.
>
> ~ Thank you,
>    Paul C Bors
>
> On Feb 26, 2013, at 23:29, Paul Bors <p...@bors.ws> wrote:
>
> > There is a wiki page on that:
> > https://cwiki.apache.org/WICKET/how-to-write-json-response.html
> >
> > ~ Thank you,
> >    Paul C Bors
> >
> > On Feb 26, 2013, at 20:33, abarretto <abarrett...@gmail.com> wrote:
> >
> >> Hi,
> >>
> >> I'm a beginner in Wicket and I need to develop a simple application that
> >> make an AJAX request to an URL using a link, which must return a JSON
> >> response. I need to handle the content of this response to show it in a
> div
> >> of the page (without reload it, of course).
> >>
> >> So, I have the url that returns the JSON response, like this:
> >> http:localhost/offices. My simple application seems like this:
> >>
> >> ------------------ MyAjax.java
> >> -----------------------------------------------------
> >>
> >> public class MyAjax extends WebPage {
> >>
> >>    private static final long serialVersionUID = 1L;
> >>
> >>    private final class MyLink extends AjaxFallbackLink {
> >>        public MyLink(String id) {
> >>            super(id);
> >>        }
> >>
> >>        public void onClick(AjaxRequestTarget target){}
> >>
> >>        public void updateAjaxAttributes(AjaxRequestAttributes
> attributes) {
> >>
> >>            super.updateAjaxAttributes(attributes);
> >>            attributes.setDataType("json");
> >>            attributes.setWicketAjaxResponse(false);
> >>
> >>            AjaxCallListener listener = new AjaxCallListener() {
> >>                private static final long serialVersionUID = 1L;
> >>                CharSequence handler =
> >> "$(\"#content\").text(data.offices[0].officeCode)";
> >>
> >>                @Override
> >>                public CharSequence getSuccessHandler(Component
> component) {
> >>                    return handler;
> >>                }
> >>              };
> >>             attributes.getAjaxCallListeners().add(listener);
> >>        }
> >>
> >>        protected void onComponentTag(ComponentTag tag) {
> >>            super.onComponentTag(tag);
> >>            String url = "/offices";
> >>            tag.put("href", url);
> >>        }
> >>    }
> >>
> >>    public MyAjax(final PageParameters parameters) {
> >>        super(parameters);
> >>        MyLink ajaxLink = new MyLink("ajaxLink");
> >>        add(ajaxLink);
> >>    }
> >> }
> >> ------------------------------------------------------
> >> ----------------- MyAjax.html ------------------------
> >> <html>
> >> <head>
> >> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
> >> <title>MyAjax Application</title>
> >> </head>
> >> <body>
> >> Get JSON <br>
> >> <div id = "content" />
> >> </body>
> >> </html>
> >> --------------------------------------------------
> >> When the MyAjax.html is rendered, I can see that the link "GET JSON"
> point
> >> to URL /offices (that return the JSON response), but, when it is
> clicked, it
> >> doesn't go to that URL. Indeed, it makes a request to an URL generated
> >> automatically by AjaxFallbackLink, something like
> >> http:/localhost/myajax/?-1.IBehavoirListener.-ajaxLink=<some_number>
> >>
> >> Additionally, an Javascript code is generated after MyAjax.html is
> rendered
> >> to indicate the url of the Ajax Request. Something like this:
> >>
> >> ----------------------- MyAjax.html (rendered) -------------------------
> >> Wicket.Event.add(window, "domready", function(event) {
> >>
> Wicket.Ajax.ajax({"dt":"json"*,"u":"./?0-1.IBehaviorListener.0-ajaxLink"*,"e":"click","c":"ajaxLink","wr":false,"sh":[function(attrs,
> >> jqXHR, data, textStatus){var response = ""; for(var i = 0; i <
> >> data.offices.length; i++) {response += data.offices[i].officeCode + "; "
> >> }$("#content").text(response)}]});;
> >> ;});
> >> .....
> >> href="/mgm/JSONOffice"*>Get JSON <br>
> >>
> >>
> >> My question is: Can I set this automatically link in a way that it uses
> my
> >> JSON URL? If not, there is a way that a can access an URL that returns a
> >> JSON response and handle the response to show it in the page?
> >>
> >> Thanks.
> >> Anderson
> >>
> >>
> >>
> >> --
> >> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Handle-JSON-response-tp4656838.html
> >> Sent from the Users forum 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
> >>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Reply via email to