@Retention(value=RUNTIME) @Target(value={PARAMETER,ANNOTATION_TYPE}) @Documented public @interface ResourceParam
request's resource resolver
. If the annotated
parameter's type is not assignable from
Resource
,
the resolved resource is adapted
to the target type. Otherwise,
the resolved resource is provided.
Example:
@Controller
@RequestMapping(produces = "text/plain")
public class MyController {
@RequestMapping("/echoTitle")
@ResponseBody
public String echoTitle(@ResourceParam
Page page) {
return page.getTitle();
}
}
In the above example, a request parameter "page" is expected. The parameter value is regarded as a
resource path and the corresponding resource is
resolved
.
The resolved resource is subsequently adapted to "Page":
GET /bin/mvc.do/echoTitle?path=/content/site/en: "English page title".
One may also append a segment to the path prior to resolution, for instance to target a sub resource of the provided path, like so:
public String echoTitle(@ResourceParam(append = "jcr:content") PageContent content) { return page.getTitle(); }The append path is also applied to the default value, if provided. By default, @
ResourceParam
parameters are required
. If the parameter is missing,
cannot be resolved to an existing resource or cannot be adapted to the required target type, an exception is thrown.
Accordingly, the parameter provided to the controller method is guaranteed not to be null
if it is required.
Consequently, the parameter may be null if either the parameter value is missing, cannot
be resolved to an existing resource or if the resolved resource cannot be adapted to the required target type
when the parameter is not required
. If a default value
is provided,
the parameter is always optional, regardless whether it is required
.
If the default value cannot be resolved, the parameter provided to the method is null
.public abstract String value
public abstract boolean required
true
, the resolved parameter is guaranteed not to be null
.public abstract String defaultValue
null
or empty, this default value is used in case no value is provided for this request parameter.
Providing a default value implies required()
= false.public abstract String append
Copyright © 2024. All rights reserved.