Re: Wicket 1.5 - Generic JSON Response
Martin Grigorov-4 wrote > > On Thu, Apr 12, 2012 at 7:38 AM, Ahijah <darren.greer@> wrote: > > mountResource("/Feed2", new MyResourceReference()); > > class MyResourceReference extends ResourceReference { > public IResource getResource() { return new MyResource(); } > } > Thanks Martin! For everyone else's reference, the final code that is working looks like this: --Feed.class public class Feed extends AbstractResource { private static final long serialVersionUID = 1L; protected ResourceResponse newResourceResponse(Attributes a) { ResourceResponse r = new ResourceResponse(); r.setContentType("application/json"); r.setWriteCallback(new WriteCallback() { public void writeData(Attributes a) { a.getResponse().write("[{\"id\":111,\"title\":\"MainEvent\",\"start\":\"2012-04-10T07:00:00\",\"end\":\"2012-04-10T09:30:00\",\"url\":\"?EventID=111\",\"allDay\":false}]"); } }); return r; } } ---End Feed.class-- --Application.class @Override protected void init() { super.init(); mountResource("/Feed", new FeedReference()); } public class FeedReference extends ResourceReference { public FeedReference() { super(FeedReference.class, "feed"); } public IResource getResource() { return new Feed(); } } ---End Application.class- -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-Generic-JSON-Response-tp4550807p4551752.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
Re: Wicket 1.5 - Generic JSON Response
Thanks for the tip, that definitely sounds like the way to go. Quick follow-up, how does one mount an AbstractResource within the application. There doesn't appear to be an Abstract reference class to instantiate using something like: mountResource("/Feed2", new ResourceReference(Feed2.class)); Thanks again! -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-Generic-JSON-Response-tp4550807p4550948.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
Wicket 1.5 - Generic JSON Response
I've been working on various implementations of this all day, to try and output a simple JSON response, as Content-Type: application/json, with absolutely no luck. My current class is setup as below. However, when sending a request to the "Feed" URL, it comes back as text/plain, with the JSON formatted string embedded below. What am I doing wrong? Thanks. - public class Feed extends WebPage implements IMarkupResourceStreamProvider { private static final long serialVersionUID = 1L; @Override protected void configureResponse(WebResponse response) { super.configureResponse(response); response.setContentType("application/json"); response.addHeader("Content-Type", "application/json"); } @Override public void renderPage() { getResponse().write("[{'id':111,'title':'MainEvent','start':'2012-04-10T07:00:00','end':'2012-04-10T09:30:00','url':'?EventID=111','allDay':false}]"); } public IResourceStream getMarkupResourceStream(MarkupContainer container, Class containerClass) { return new StringResourceStream(""); } } -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-Generic-JSON-Response-tp4550807p4550807.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