Skip to content

Expose model object in RequestContext with public getter [SPR-5686] #10356

Closed
@spring-projects-issues

Description

@spring-projects-issues

Dave Syer opened SPR-5686 and commented

Expose model object in RequestContext. Background:

Trying to use Freemarker with Tiles, and I want to manipulate the model from an "enclosing" request and, while I can get hold of the RequestContext via the AbstractTemplateView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE, but then I can only get the model by using Field.setAccessible(true), e.g.

String contextAttribute = AbstractTemplateView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE;
RequestContext context = (RequestContext) request
		.getAttribute(contextAttribute);
if (context != null) {
	@SuppressWarnings("unchecked")
	Map<String, Object> model = (Map<String, Object>) MacroModelInterceptor
			.getField(context, "model");
	model.remove(contextAttribute);
	modelAndView.addAllObjects(model);
	request.removeAttribute(contextAttribute);
}

Affects: 2.5.6

Referenced from: commits c230c18

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions