tags:

views:

117

answers:

1

Hi!

it seems i cant wrap my Head around how to implment a custom ViewProcessor in Jersey. Ihave the following Resource:

@Path("/events")
public class EventController extends AbstractController {
    private static final Logger LOG = LoggerFactory.getLogger(EventController.class);

    @Resource(name = "eventService")
    private EventService eventService;

    public void setEventService(EventService eventService) {
        this.eventService = eventService;
    }

    @GET
    @Produces(MediaType.TEXT_HTML)
    public Viewable viewEventsAsHtml() {
        Map<String, String> model = new HashMap<String, String>();
        model.put("msg", "test");
        return new Viewable("/events.jsp", model);
    }
}

since i want to organize my jsp views in "/WEB-INF/views/jsp" i extended JSPTemplateProcessor thusly:

public class CJJspTemplateProcessor extends JSPTemplateProcessor {
    private static final Logger LOG = LoggerFactory.getLogger(CJJspTemplateProcessor.class);

    private final String basePath = "/WEB-INF/views/jsp";

    public CJJspTemplateProcessor(@Context ResourceConfig resourceConfig) {
        super(resourceConfig);
    }

    @Override
    public String resolve(String name) {
        String path;
        if (!name.endsWith(".jsp")) {
            name += ".jsp";
        }
        path = basePath + name;
        LOG.debug("resolving " + name + " to " + path);
        return path;
    }
}

but when i navigate to the event resource i get an 404, although i can see that the TemplateProcessor resolved the right path for the jsp in the logfiles.

plx help :)

+1  A: 

You don't need a custom TemplateProcessor to do this simple add the following to the filter element in your web.xml.

<filter>
    <init-param>
        <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
        <param-value>/WEB-INF/views/jsp</param-value>
    </init-param>
</filter>
Alex Winston
this worked but only if i used a filter configuration in web.xml. but it does not work when using a servlet config :/
smeg4brains