01: /*
02: * Created on Jul 16, 2006
03: */
04: package uk.org.ponder.rsf.springmvc;
05:
06: import java.util.Iterator;
07: import java.util.Locale;
08: import java.util.Map;
09:
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12:
13: import org.springframework.validation.Errors;
14: import org.springframework.web.servlet.support.RequestContextUtils;
15: import org.springframework.web.servlet.view.AbstractTemplateView;
16:
17: import uk.org.ponder.beanutil.WriteableBeanLocator;
18: import uk.org.ponder.messageutil.TargettedMessageList;
19: import uk.org.ponder.rsac.RSACBeanLocator;
20: import uk.org.ponder.rsac.servlet.RSACUtils;
21: import uk.org.ponder.rsf.request.EarlyRequestParser;
22: import uk.org.ponder.springutil.errors.SpringErrorConverter;
23: import uk.org.ponder.util.Logger;
24:
25: public class IKATView extends AbstractTemplateView {
26: public static final String SPRING_MVC_VIEW_NAME = "springMVC-View";
27:
28: protected void renderMergedTemplateModel(Map model,
29: HttpServletRequest request, HttpServletResponse response)
30: throws Exception {
31: RSACBeanLocator rsacbeanlocator = (RSACBeanLocator) getApplicationContext()
32: .getBean(RSACBeanLocator.RSAC_BEAN_LOCATOR_NAME);
33: RSACUtils.startServletRequest(request, response,
34: rsacbeanlocator, RSACUtils.HTTP_SERVLET_FACTORY);
35: WriteableBeanLocator requestwbl = rsacbeanlocator
36: .getBeanLocator();
37: try {
38: // refocus from the billion random vectors all the dependencies that this
39: // request will require.
40: requestwbl.set(SPRING_MVC_VIEW_NAME, getBeanName());
41: requestwbl
42: .set("SpringMVC-RCAttributes", getAttributesMap());
43: try {
44: final Locale locale = RequestContextUtils
45: .getLocale(request);
46: requestwbl.set("requestLocale", locale);
47: } catch (Exception e) {
48: Logger.log.warn("Error acquiring locale from request",
49: e);
50: }
51: // temporary - request context appears not to be set in our pipeline.
52: // String requestcontextattr = getRequestContextAttribute();
53: // final RequestContext rc = (RequestContext)
54: // getAttributesMap().get(requestcontextattr);
55:
56: TargettedMessageList tml = (TargettedMessageList) requestwbl
57: .locateBean("targettedMessageList");
58: // We will ignore the ContentType, as per the comment in AbstractView -
59: // RSF content type determination provides a higher point of control.
60: // Throw in the model, so that ViewProducer EL may reference it
61: for (Iterator mit = model.keySet().iterator(); mit
62: .hasNext();) {
63: String key = (String) mit.next();
64: Object value = model.get(key);
65: if (value instanceof Errors) {
66: Errors errors = (Errors) value;
67: SpringErrorConverter.appendErrors(errors
68: .getNestedPath(), tml, errors);
69: }
70: requestwbl.set(key, value);
71: }
72: // prevent RSF/IKAT from applying redirect-on-error semantics - this will
73: // totally break SpringMVC's navigation.
74: requestwbl.set("redirectOnLevel1Error", Boolean.FALSE);
75: requestwbl.set("renderFossilizedForms", Boolean.FALSE);
76: // SpringMVC will try to render off POSTs in the case of validation failure
77: requestwbl.set("requestType",
78: EarlyRequestParser.RENDER_REQUEST);
79: // Do IIIT.
80: rsacbeanlocator.getBeanLocator().locateBean(
81: "rootHandlerBean");
82: } finally {
83: rsacbeanlocator.endRequest();
84: }
85: }
86: }
|