Package org.springframework.web.servlet.view

# Interface FragmentsRendering

All Superinterfaces:
  `SmartView`, `View`

public interface FragmentsRendering extends SmartView
Public API to render HTML fragments. A fragment is a portion of an HTML page. Normally HTML is rendered with a single model and view. This API allows using multiple model and view pairs, one for each HTML fragment.

For use with frontends technologies such as htmx where multiple page fragments may be rendered in one response.

Supported as a return value from controller methods.

Since:
  6.2
Author:
  Rossen Stoyanchev

## Nested Class Summary

Nested Classes
Modifier and Type
Interface
Description
`static interface`
`FragmentsRendering.Builder`
Defines a builder for `FragmentsRendering`.

## Field Summary

### Fields inherited from interface org.springframework.web.servlet.View

`PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE`

## Method Summary

Modifier and Type
Method
Description
`static FragmentsRendering.Builder`
`fragment(String viewName)`
Create a builder with one HTML fragment, also inheriting attributes from the shared model for the request.
`static FragmentsRendering.Builder`
`fragment(String viewName, Map<String,Object> model)`
Create a builder with one HTML fragment.
`Collection<ModelAndView>`
`fragments()`
Return the `ModelAndView` for each fragment.
`static FragmentsRendering.Builder`
`fragments(Collection<ModelAndView> fragments)`
Create a builder with multiple HTML fragments.
`org.springframework.http.HttpHeaders`
`headers()`
Return headers to add to the response.
`org.springframework.http.HttpStatusCode`
`status()`
Return the HTTP status to set the response to.
`static FragmentsRendering.Builder`
`with(String viewName)`
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `fragment(String)`
`static FragmentsRendering.Builder`
`with(String viewName, Map<String,Object> model)`
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `fragment(String, Map)`
`static FragmentsRendering.Builder`
`with(Collection<ModelAndView> fragments)`
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `fragments(Collection)`

### Methods inherited from interface org.springframework.web.servlet.SmartView

`isRedirectView, resolveNestedViews`

### Methods inherited from interface org.springframework.web.servlet.View

`getContentType, render`

## 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

Collection<ModelAndView> fragments()
Return the `ModelAndView` for each fragment.

Since:
  6.2.15

### fragment

static FragmentsRendering.Builder fragment(String viewName)
Create a builder with one HTML fragment, also inheriting attributes from the shared model for the request.

Parameters:
  `viewName` - the name of the view for the fragment
Returns:
  the created builder
Since:
  6.2.13

### fragment

static FragmentsRendering.Builder fragment(String viewName, Map<String,Object> model)
Create a builder with one HTML fragment.

Parameters:
  `viewName` - the view name for the fragment
  `model` - attributes for the fragment, in addition to attributes from the shared model for the request
Returns:
  the created builder
Since:
  6.2.13

### fragments

static FragmentsRendering.Builder fragments(Collection<ModelAndView> fragments)
Create a builder with multiple HTML fragments.

Parameters:
  `fragments` - the fragments to add; each fragment also inherits attributes from the shared model for the request
Returns:
  the created builder
Since:
  6.2.13

### with

@Deprecated(since="6.2.13", forRemoval=true) static FragmentsRendering.Builder with(String viewName, Map<String,Object> model)
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `fragment(String, Map)`
The same as `fragment(String, Map)`.

### with

@Deprecated(since="6.2.13", forRemoval=true) static FragmentsRendering.Builder with(String viewName)
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `fragment(String)`
The same as `fragment(String)`.

### with

@Deprecated(since="6.2.13", forRemoval=true) static FragmentsRendering.Builder with(Collection<ModelAndView> fragments)
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `fragments(Collection)`
The same as `fragments(Collection)`.