You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

In your WebPage...

...

public class JsonWebPage extends WebPage {

	public JsonWebPage(PageParameters pageParameters) {

		getRequestCycle().scheduleRequestHandlerAfterCurrent(new IRequestTarget() {

			@Override
			public void detach(RequestCycle requestCycle) {
				// Nothing to do here.
			}

			@Override
			public void respond(RequestCycle requestCycle) {
				// Add JSON-encoded string to the response.
				requestCycle.getResponse().write("{\"jsonKey\":\"jsonValue\"}");
			}

		});

	}

}
...

NOTE: You DO NOT need to manually write JSON response, there are libraries like http://json-lib.sourceforge.net/ available that will allow you to convert an object hierarchy to something more useful in terms of JSON rather easily. For details, check the documentation at: http://json-lib.sourceforge.net/usage.html.

Another library for JSON processing/generation is jackson.

NOTE Wicket >= 1.5.x: see https://github.com/wicketstuff/core/tree/master/jdk-1.6-parent/autocomplete-tagit-parent for an example

  • No labels