Skip to content

Commit 8ad95b0

Browse files
committed
ReactiveContext and BindStatus in spring-web-reactive
Issue: SPR-14533
1 parent 136b33b commit 8ad95b0

File tree

5 files changed

+900
-0
lines changed

5 files changed

+900
-0
lines changed

spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public abstract class AbstractView implements View, ApplicationContextAware {
4949

5050
private Charset defaultCharset = StandardCharsets.UTF_8;
5151

52+
private String requestContextAttribute;
53+
5254
private ApplicationContext applicationContext;
5355

5456

@@ -95,6 +97,21 @@ public Charset getDefaultCharset() {
9597
return this.defaultCharset;
9698
}
9799

100+
/**
101+
* Set the name of the RequestContext attribute for this view.
102+
* Default is none.
103+
*/
104+
public void setRequestContextAttribute(String requestContextAttribute) {
105+
this.requestContextAttribute = requestContextAttribute;
106+
}
107+
108+
/**
109+
* Return the name of the RequestContext attribute, if any.
110+
*/
111+
public String getRequestContextAttribute() {
112+
return this.requestContextAttribute;
113+
}
114+
98115
@Override
99116
public void setApplicationContext(ApplicationContext applicationContext) {
100117
this.applicationContext = applicationContext;
@@ -126,6 +143,12 @@ public Mono<Void> render(Map<String, ?> model, MediaType contentType,
126143
}
127144

128145
Map<String, Object> mergedModel = getModelAttributes(model, exchange);
146+
147+
// Expose RequestContext?
148+
if (this.requestContextAttribute != null) {
149+
mergedModel.put(this.requestContextAttribute, createRequestContext(exchange, mergedModel));
150+
}
151+
129152
return renderInternal(mergedModel, contentType, exchange);
130153
}
131154

@@ -145,6 +168,20 @@ protected Map<String, Object> getModelAttributes(Map<String, ?> model, ServerWeb
145168
return attributes;
146169
}
147170

171+
/**
172+
* Create a RequestContext to expose under the specified attribute name.
173+
* <p>The default implementation creates a standard RequestContext instance for the
174+
* given request and model. Can be overridden in subclasses for custom instances.
175+
* @param exchange current exchange
176+
* @param model combined output Map (never {@code null}),
177+
* with dynamic values taking precedence over static attributes
178+
* @return the RequestContext instance
179+
* @see #setRequestContextAttribute
180+
*/
181+
protected RequestContext createRequestContext(ServerWebExchange exchange, Map<String, Object> model) {
182+
return new RequestContext(exchange, model, this.applicationContext);
183+
}
184+
148185
/**
149186
* Subclasses must implement this method to actually render the view.
150187
* @param renderAttributes combined output Map (never {@code null}),

0 commit comments

Comments
 (0)