I’m trying to use Mootools (Request.JSON) together with JSF – mainly because I wrote a similar application in CakePHP some time ago and would like to reuse most of the JS part.
Is there any way to return plain text (“application/json”) using an request from something like a markup-less facelet?
The only solution I came up with was using an HttpServlet and registering it to a service URL in web.xml. That approach works and really returns an file without any markup, but I’d rather use my Spring-injected ManagedProperties than being restricted to WebApplicationContextUtils.
Did I miss something or is that the recommended way?
There is a way. But it’s ugly and essentially abuse of JSF/Facelets as in using the wrong tool for the job.
E.g.
with
Much better is to use a JAX-RS web service. I’m not sure if Spring managed beans are injectable in there, but the new Java EE 6 CDI allows you to inject
@Namedbeans everywhere by@Inject, even in a simple@WebServlet.See also: