|
|
|
@ -17,7 +17,6 @@ |
|
|
|
package org.springframework.web.reactive.result.view; |
|
|
|
package org.springframework.web.reactive.result.view; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.function.Consumer; |
|
|
|
import java.util.function.Consumer; |
|
|
|
|
|
|
|
|
|
|
|
@ -65,15 +64,62 @@ public interface FragmentsRendering { |
|
|
|
Flux<Fragment> fragments(); |
|
|
|
Flux<Fragment> fragments(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create a builder with one HTML fragment, also inheriting attributes from |
|
|
|
|
|
|
|
* the shared model for the request. |
|
|
|
|
|
|
|
* @param viewName the name of the view for the fragment |
|
|
|
|
|
|
|
* @return this builder |
|
|
|
|
|
|
|
* @since 6.2.1 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static Builder fragment(String viewName) { |
|
|
|
|
|
|
|
return new DefaultFragmentsRenderingBuilder().fragment(viewName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a builder with one HTML fragment. |
|
|
|
* Create a builder with one HTML fragment. |
|
|
|
* @param viewName the view name for the fragment |
|
|
|
* @param viewName the view name for the fragment |
|
|
|
* @param model attributes for the fragment, in addition to attributes from the |
|
|
|
* @param model attributes for the fragment, in addition to attributes from the |
|
|
|
* shared model for the request |
|
|
|
* shared model for the request |
|
|
|
* @return this builder |
|
|
|
* @return this builder |
|
|
|
|
|
|
|
* @since 6.2.1 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static Builder with(String viewName, Map<String, Object> model) { |
|
|
|
static Builder fragment(String viewName, Map<String, Object> model) { |
|
|
|
return withCollection(List.of(Fragment.create(viewName, model))); |
|
|
|
return new DefaultFragmentsRenderingBuilder().fragment(viewName, model); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create a builder with multiple HTML fragments. |
|
|
|
|
|
|
|
* @param fragments the fragments to add; each fragment also inherits |
|
|
|
|
|
|
|
* attributes from the shared model for the request |
|
|
|
|
|
|
|
* @return the created builder |
|
|
|
|
|
|
|
* @since 6.2.1 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static Builder fragments(Collection<Fragment> fragments) { |
|
|
|
|
|
|
|
return new DefaultFragmentsRenderingBuilder().fragments(fragments); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create a builder with a {@link Publisher} of fragments. |
|
|
|
|
|
|
|
* @param fragmentsPublisher the fragments to add; each fragment also |
|
|
|
|
|
|
|
* inherits model attributes from the shared model for the request |
|
|
|
|
|
|
|
* @return the created builder |
|
|
|
|
|
|
|
* @since 6.2.1 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static <P extends Publisher<Fragment>> Builder fragmentsPublisher(P fragmentsPublisher) { |
|
|
|
|
|
|
|
return new DefaultFragmentsRenderingBuilder(fragmentsPublisher); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Variant of {@link #fragmentsPublisher(Publisher)} that allows using any |
|
|
|
|
|
|
|
* producer that can be resolved to {@link Publisher} via |
|
|
|
|
|
|
|
* {@link ReactiveAdapterRegistry}. |
|
|
|
|
|
|
|
* @since 6.2.1 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static Builder fragmentsProducer(Object fragmentsProducer) { |
|
|
|
|
|
|
|
ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(fragmentsProducer.getClass()); |
|
|
|
|
|
|
|
Assert.isTrue(adapter != null, "Unknown producer " + fragmentsProducer.getClass()); |
|
|
|
|
|
|
|
Publisher<Fragment> publisher = adapter.toPublisher(fragmentsProducer); |
|
|
|
|
|
|
|
return fragmentsPublisher(publisher); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -81,9 +127,24 @@ public interface FragmentsRendering { |
|
|
|
* the shared model for the request. |
|
|
|
* the shared model for the request. |
|
|
|
* @param viewName the name of the view for the fragment |
|
|
|
* @param viewName the name of the view for the fragment |
|
|
|
* @return this builder |
|
|
|
* @return this builder |
|
|
|
|
|
|
|
* @deprecated in favor of {@link #fragment(String)} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated(since = "6.2.1", forRemoval = true) |
|
|
|
static Builder with(String viewName) { |
|
|
|
static Builder with(String viewName) { |
|
|
|
return withCollection(List.of(Fragment.create(viewName))); |
|
|
|
return fragment(viewName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create a builder with one HTML fragment. |
|
|
|
|
|
|
|
* @param viewName the view name for the fragment |
|
|
|
|
|
|
|
* @param model attributes for the fragment, in addition to attributes from the |
|
|
|
|
|
|
|
* shared model for the request |
|
|
|
|
|
|
|
* @return this builder |
|
|
|
|
|
|
|
* @deprecated in favor of {@link #fragment(String, Map)} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated(since = "6.2.1", forRemoval = true) |
|
|
|
|
|
|
|
static Builder with(String viewName, Map<String, Object> model) { |
|
|
|
|
|
|
|
return fragment(viewName, model); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -91,9 +152,11 @@ public interface FragmentsRendering { |
|
|
|
* @param fragments the fragments to add; each fragment also inherits |
|
|
|
* @param fragments the fragments to add; each fragment also inherits |
|
|
|
* attributes from the shared model for the request |
|
|
|
* attributes from the shared model for the request |
|
|
|
* @return the created builder |
|
|
|
* @return the created builder |
|
|
|
|
|
|
|
* @deprecated in favor of {@link #fragments(Collection)} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated(since = "6.2.1", forRemoval = true) |
|
|
|
static Builder withCollection(Collection<Fragment> fragments) { |
|
|
|
static Builder withCollection(Collection<Fragment> fragments) { |
|
|
|
return new DefaultFragmentsRenderingBuilder(fragments); |
|
|
|
return fragments(fragments); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -101,24 +164,22 @@ public interface FragmentsRendering { |
|
|
|
* @param fragmentsPublisher the fragments to add; each fragment also |
|
|
|
* @param fragmentsPublisher the fragments to add; each fragment also |
|
|
|
* inherits model attributes from the shared model for the request |
|
|
|
* inherits model attributes from the shared model for the request |
|
|
|
* @return the created builder |
|
|
|
* @return the created builder |
|
|
|
|
|
|
|
* @deprecated in favor of {@link #fragmentsPublisher(Publisher)} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated(since = "6.2.1", forRemoval = true) |
|
|
|
static <P extends Publisher<Fragment>> Builder withPublisher(P fragmentsPublisher) { |
|
|
|
static <P extends Publisher<Fragment>> Builder withPublisher(P fragmentsPublisher) { |
|
|
|
return new DefaultFragmentsRenderingBuilder(fragmentsPublisher); |
|
|
|
return fragmentsPublisher(fragmentsPublisher); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Variant of {@link #withPublisher(Publisher)} that allows using any |
|
|
|
* Variant of {@link #fragmentsPublisher(Publisher)} that allows using any |
|
|
|
* producer that can be resolved to {@link Publisher} via |
|
|
|
* producer that can be resolved to {@link Publisher} via |
|
|
|
* {@link ReactiveAdapterRegistry}. |
|
|
|
* {@link ReactiveAdapterRegistry}. |
|
|
|
|
|
|
|
* @deprecated in favor of {@link #fragmentsProducer(Object)} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated(since = "6.2.1", forRemoval = true) |
|
|
|
static Builder withProducer(Object fragmentsProducer) { |
|
|
|
static Builder withProducer(Object fragmentsProducer) { |
|
|
|
return new DefaultFragmentsRenderingBuilder(adaptProducer(fragmentsProducer)); |
|
|
|
return fragmentsProducer(fragmentsProducer); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Publisher<Fragment> adaptProducer(Object producer) { |
|
|
|
|
|
|
|
ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(producer.getClass()); |
|
|
|
|
|
|
|
Assert.isTrue(adapter != null, "Unknown producer " + producer.getClass()); |
|
|
|
|
|
|
|
return adapter.toPublisher(producer); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -169,11 +230,21 @@ public interface FragmentsRendering { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Add an HTML fragment. |
|
|
|
* Add an HTML fragment. |
|
|
|
* @param fragment the fragment to add |
|
|
|
* @param fragment the fragment to add; the fragment also inherits |
|
|
|
|
|
|
|
* attributes from the shared model for the request |
|
|
|
* @return this builder |
|
|
|
* @return this builder |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Builder fragment(Fragment fragment); |
|
|
|
Builder fragment(Fragment fragment); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Add HTML fragments. |
|
|
|
|
|
|
|
* @param fragments the fragments to add; each fragment also inherits |
|
|
|
|
|
|
|
* attributes from the shared model for the request |
|
|
|
|
|
|
|
* @return this builder |
|
|
|
|
|
|
|
* @since 6.2.1 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Builder fragments(Collection<Fragment> fragments); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Build the {@link FragmentsRendering} instance. |
|
|
|
* Build the {@link FragmentsRendering} instance. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|