ViewResolver that allows direct resolution of symbolic view names
to URLs without explicit mapping definitions. This is useful if symbolic names
match the names of view resources in a straightforward manner (i.e. the
symbolic name is the unique part of the resource's filename), without the need
for a dedicated mapping to be defined for each view.
Supports AbstractUrlBasedView subclasses like
org..
The view class for all views generated by this resolver can be specified
via the "viewClass" property.
View names can either be resource URLs themselves, or get augmented by a specified prefix and/or suffix. Exporting an attribute that holds the RequestContext to all views is explicitly supported.
Example: prefix="templates/", suffix=".ftl", viewname="test" → "templates/test.ftl"
As a special feature, redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction" will trigger a redirect to the given URL, rather than resolution as standard view name. This is typically used for redirecting to a controller URL after finishing a form workflow.
Note
This class does not support localized resolution, i.e. resolving a symbolic view name to different resources depending on the current locale.
| Modifier and Type | Field and Description |
|---|---|
| private ApplicationContext | |
| private String | |
| public static final String | REDIRECT_URL_PREFIX
Prefix for special view names that specify a redirect URL (usually to a controller after a form has been submitted and processed). |
| private Function | |
| private String | |
| private String | |
| private Class | |
| private String[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| protected View | Returns: theView instance to use (either the original one
or a decorated variant)the name of the view viewName, AbstractUrlBasedView the freshly created View instance, pre-configured with
view)AbstractUrlBasedView's propertiesApply the containing |
| protected boolean | Returns: whether this resolver applies to the specified viewthe name of the view to retrieve viewName, Locale the Locale to retrieve the view for locale)Indicates whether this |
| protected AbstractUrlBasedView | Returns: the View instancethe name of the view to build viewName)Creates a new View instance of the specified view class and configures it. |
| public ApplicationContext | |
| protected String | |
| protected String | |
| protected String | |
| protected Class | |
| protected String[] | |
| protected AbstractUrlBasedView | |
| protected Class | |
| public Mono | resolveViewName(String
the name of the view to resolve viewName, Locale the locale for the request locale)Implements org. Resolve the view name to a View instance. |
| public void | setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object applicationContext)Implements org. Accept the containing |
| public void | |
| public void | setRedirectViewProvider(Function<String, RedirectView> redirectViewProvider)
URL based |
| public void | setRequestContextAttribute(String
name of the RequestContext attribute requestContextAttribute)Set the name of the |
| public void | |
| public void | setViewClass(Class<?>
a class that is assignable to the required view class
(by default: AbstractUrlBasedView) viewClass)Set the view class that should be used to create views. |
| public void | setViewNames(String... viewNames)
Set the view names (or name patterns) that can be handled by this
|
| applicationContext | back to summary |
|---|---|
| private ApplicationContext applicationContext
| |
| prefix | back to summary |
|---|---|
| private String prefix | |
| REDIRECT_URL_PREFIX | back to summary |
|---|---|
| public static final String REDIRECT_URL_PREFIX Prefix for special view names that specify a redirect URL (usually to a controller after a form has been submitted and processed). Such view names will not be resolved in the configured default way but rather be treated as special shortcut. | |
| redirectViewProvider | back to summary |
|---|---|
| private Function<String, RedirectView> redirectViewProvider | |
| requestContextAttribute | back to summary |
|---|---|
| private String requestContextAttribute
| |
| suffix | back to summary |
|---|---|
| private String suffix | |
| viewClass | back to summary |
|---|---|
| private Class<?> viewClass
| |
| viewNames | back to summary |
|---|---|
| private String[] viewNames
| |
| UrlBasedViewResolver | back to summary |
|---|---|
| public UrlBasedViewResolver() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() throws Exception Implements org. Doc from org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. | |
| applyLifecycleMethods | back to summary |
|---|---|
| protected View applyLifecycleMethods(String viewName, AbstractUrlBasedView view) Apply the containing
| |
| canHandle | back to summary |
|---|---|
| protected boolean canHandle(String viewName, Locale locale) Indicates whether this
| |
| createView | back to summary |
|---|---|
| protected AbstractUrlBasedView createView(String viewName) Creates a new View instance of the specified view class and configures it. Does not perform any lookup for pre-defined View instances. Spring lifecycle methods as defined by the bean container do not have to
be called here: They will be automatically applied afterwards, provided
that an
| |
| getApplicationContext | back to summary |
|---|---|
| public ApplicationContext getApplicationContext() Return the containing
| |
| getPrefix | back to summary |
|---|---|
| protected String getPrefix() Return the prefix that gets prepended to view names when building a URL. | |
| getRequestContextAttribute | back to summary |
|---|---|
| protected String getRequestContextAttribute() Return the name of the
| |
| getSuffix | back to summary |
|---|---|
| protected String getSuffix() Return the suffix that gets appended to view names when building a URL. | |
| getViewClass | back to summary |
|---|---|
| protected Class Return the view class to be used to create views.
| |
| getViewNames | back to summary |
|---|---|
| protected String[] getViewNames() Return the view names (or name patterns) that can be handled by this
| |
| instantiateView | back to summary |
|---|---|
| protected AbstractUrlBasedView instantiateView() Instantiate the specified view class. The default implementation uses reflection to instantiate the class.
| |
| requiredViewClass | back to summary |
|---|---|
| protected Class Return the required type of view for this resolver.
This implementation returns
| |
| resolveViewName | back to summary |
|---|---|
| public Mono Implements org. Doc from org. Resolve the view name to a View instance. | |
| setApplicationContext | back to summary |
|---|---|
| public void setApplicationContext(ApplicationContext applicationContext) Implements org. Accept the containing To be used for the initialization of newly created
| |
| setPrefix | back to summary |
|---|---|
| public void setPrefix(String prefix) Set the prefix that gets prepended to view names when building a URL. | |
| setRedirectViewProvider | back to summary |
|---|---|
| public void setRedirectViewProvider(Function<String, RedirectView> redirectViewProvider) URL based | |
| setRequestContextAttribute | back to summary |
|---|---|
| public void setRequestContextAttribute(String requestContextAttribute) Set the name of the
| |
| setSuffix | back to summary |
|---|---|
| public void setSuffix(String suffix) Set the suffix that gets appended to view names when building a URL. | |
| setViewClass | back to summary |
|---|---|
| public void setViewClass(Class<?> viewClass) Set the view class that should be used to create views.
| |
| setViewNames | back to summary |
|---|---|
| public void setViewNames(String... viewNames) Set the view names (or name patterns) that can be handled by this
| |