Interface FragmentsRendering


public interface FragmentsRendering
Public API for HTML rendering of a collection of fragments each with a view and independent model. For use with frontends technologies such as htmx where multiple page fragments may be rendered in one response. Supported as a return value from Spring WebFlux controller methods.

For full page rendering with a single model and view, use Rendering.

Since:
6.2
Author:
Rossen Stoyanchev
  • Method Details

    • status

      @Nullable org.springframework.http.HttpStatusCode status()
      Return the HTTP status to set the response to.
    • headers

      org.springframework.http.HttpHeaders headers()
      Return headers to add to the response.
    • fragments

      reactor.core.publisher.Flux<Fragment> fragments()
      Return the fragments to render.
    • with

      static FragmentsRendering.Builder with(String viewName, Map<String,Object> model)
      Create a builder and add a fragment with a view name and a model.
      Parameters:
      viewName - the name of the view for the fragment
      model - attributes for the fragment in addition to model attributes inherited from the model for the request
      Returns:
      this builder
    • with

      static FragmentsRendering.Builder with(String viewName)
      Variant of with(String, Map) with a view name only, but also inheriting model attributes from the shared model for the request.
      Parameters:
      viewName - the name of the view for the fragment
      Returns:
      this builder
    • withCollection

      static FragmentsRendering.Builder withCollection(Collection<Fragment> fragments)
      Variant of with(String, Map) with a collection of fragments.
      Parameters:
      fragments - the fragments to add; each fragment also inherits model attributes from the shared model for the request
      Returns:
      the created builder
    • withPublisher

      static <P extends Publisher<Fragment>> FragmentsRendering.Builder withPublisher(P fragmentsPublisher)
      Variant of with(String, Map) with a Publisher of fragments.
      Parameters:
      fragmentsPublisher - the fragments to add; each fragment also inherits model attributes from the shared model for the request
      Returns:
      the created builder
    • withProducer

      static FragmentsRendering.Builder withProducer(Object fragmentsProducer)
      Variant of withPublisher(Publisher) that allows using any producer that can be resolved to Publisher via ReactiveAdapterRegistry.