- 
 @Qualifier @Retention(RUNTIME) @Target({METHOD,FIELD,PARAMETER}) public @interface Param The CDI annotation @Paramallows you to inject, convert and validate a HTTP request or path parameter in a CDI managed bean.For HTTP request parameters it's basically like <f:viewParam>, but with the major difference that the injected parameter is directly available duringPostConstruct, allowing a much easier way of processing without the need for a<f:event type="preRenderView">or<f:viewAction>in the view.UsageRequest parametersThe example below injects the request parameter with name foo.@Param private String foo; By default the name of the request parameter is taken from the name of the variable into which injection takes place. The name can be optionally specified via the nameattribute. The example below injects the request parameter with namefoointo a variable namedbar.@Param(name="foo") private String bar; The nameattribute is only mandatory when using constructor injection in OmniFaces 3.5 or older as there is no information about constructor parameter names. The example below injects the request parameter with namefooas a constructor parameter.@Inject public Bean(@Param(name="foo") String foo) { // ... }Since OmniFaces 3.6 it is not necessary anymore if the parameter has a name according to the class file as per Parameter#isNamePresent().@Inject public Bean(@Param String foo) { // ... }Multi-valued request parametersMulti-valued parameters are also supported by specifying a Listor array type. The support was added in OmniFaces 2.4.@Param(name="foo") private List<String> foos; @Param(name="bar") private String[] bars; Path parametersPath parameters can be injected by specifying the pathIndexattribute representing the zero-based index of the path parameter. The support was added in OmniFaces 2.5. On an example requesthttps://example.com/mypage/firstname.lastname, which is mapped to/mypage.xhtml, the below example injects the path parameterfirstname.lastname.@Param(pathIndex=0) private String user; This takes precedence over the nameattribute.Conversion and validationStandard types for which Faces already has a build in converter like String,Long,Boolean, etc or for which there's already a converter registered viaforClass, can be injected without explicitly specifying a converter.@Param private Long id; Other types do need a converter. The following is an example of the injection of request parameter userfollowing a request such ashttps://example.com/mypage?user=42:@Param(converter="userConverter", validator="priviledgedUser") private User user; This also works on multi-valued parameters. @Param(name="user", converter="userConverter") private List<User> users; This also works on path parameters. The following is an example of the injection of path parameter userfollowing a request such ashttps://example.com/mypage/42:@Param(pathIndex=0, converter="userConverter", validator="priviledgedUser") private User user; Note that the converterandvalidatorattributes can be specified in 3 ways:- A string value representing the converter/validator ID like so converter="userConverter".
- An EL expression returning the converter/validator ID string like so converter="#{bean.converterId}".
- An EL expression returning the concrete converter/validator instance like so converter="#{converterBean}".
 Instead of converterorvalidatoryou can also useconverterClassorvalidatorClass:@Param(converterClass=UserConverter.class, validatorClass=PriviledgedUser.class) private User user; Note that this is ignored when converterorvalidatoris also specified.In case you want to specify converter or validator attributes, then you can use converterAttributesorvalidatorAttributesrespectively. They accept an array ofAttributearguments whose value can be a string literal or an EL expression such asvalue = "#{bean.property}".@Param( converterClass = DateTimeConverter.class, converterAttributes = { @Attribute(name = "pattern", value = "yyyyMMdd") }, converterMessage = "{1}: \"{0}\" is not the date format we had in mind! Please use the format yyyyMMdd.") private Date date;Yes, you can use converterMessageandvalidatorMessageto customize the error message.In case the converted parameter value is not serializable, while the managed bean is serializable, you could inject it into a field of type ParamValue, withVthe actual type of the converted parameter. Deserialization in this case works by converting from the original parameter again.@Inject @Param(converter="someIdToInputStreamConverter") private ParamValue<InputStream> content; // Extreme example :) Be careful with resource leaking. If conversion or validation fails, nullis injected if the injection target is NOTParamValue. Otherwise aParamValueinstance is injected, but it will contain anullvalue. In both cases, the conversion and validation messages (if any) will be set in the Faces context then, andFacesContext.isValidationFailed()will returntrue.Faces MessagesBy default, faces messages are attached to the client ID of the current UIViewRoot, so you can use the followingforattribute to separate faces messages coming from@Paramfrom the rest:<h:messages for="#{view.id}" />In case you wish to make it a global message, then you can since OmniFaces 4.5 set the globalMessageattribute totrue:@Param(globalMessage=true) So that these can only be displayed via below tag:<h:messages globalOnly="true" /> Historical noteBefore OmniFaces 3.6, the @Paramwhich is not of typeParamValuealso required@Injectas in:@Inject @Param private String foo; But this is not needed anymore since OmniFaces 3.6. This has the following advantages: - Less code
- Not anymore confusing "No bean is eligible for injection to the injection point [JSR-365 ยง5.2.2]" warnings in IDEs like Eclipse (caused by the dynamic/generic type of the injection point).
 DynamicParamValueProducer. Instead the injection is "manually" done while creating the bean.- Since:
- 1.6
- Author:
- Arjan Tijms, Bauke Scholtz
- See Also:
- ParamValue,- Attribute,- ParamExtension,- ParamProducer,- DynamicParamValueProducer
 
- A string value representing the converter/validator ID like so 
- 
- 
Optional Element SummaryOptional Elements Modifier and Type Optional Element Description Stringconverter(Optional/Required) The converter to be used for converting the parameter to the type that is to be injected.Attribute[]converterAttributes(Optional) Attributes that will be set on the converter instance obtained fromconverter()orconverterClass().Class<? extends Converter>converterClass(Optional) Class of the converter to be used for converting the parameter to the type that is to be injected.StringconverterMessage(Optional) A message that will be used if conversion fails instead of the message set by the converter.booleandisableBeanValidation(Optional) Flag that disables bean validation for this instance.booleanglobalMessage(Optional) Whether to add the faces message as a global message instead of a message for the currentUIViewRoot.Stringlabel(Optional) the label used to refer to the parameter.Stringname(Optional) The name of the request parameter.booleanoverrideGlobalBeanValidationDisabled(Optional) Flag that overrides the globalBeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAMEsetting.intpathIndex(Optional) The index of the path parameter.booleanrequired(Optional) Flag indicating if this parameter is required (must be present) or not.StringrequiredMessage(Optional) A message that will be used if a non-empty value is submitted instead of the default message associated with theRequiredValidator.Attribute[]validatorAttributes(Optional) Attributes that will be set on each of the validator instances obtained fromvalidators()andvalidatorClasses().Class<? extends Validator>[]validatorClasses(Optional) Class of one ore more validators to be used for validating the (converted) parameter.StringvalidatorMessage(Optional) A message that will be used if validation fails instead of the message set by the validator(s).String[]validators(Optional) The validators to be used for validating the (converted) parameter.
 
- 
- 
- 
Element Detail- 
nameString name (Optional) The name of the request parameter. If not specified the name of the injection target field will be used.- Returns:
- The name of the request parameter.
 - Default:
- ""
 
 
- 
 - 
- 
pathIndexint pathIndex (Optional) The index of the path parameter. If specified the parameter will be extracted from the request path info on the given index instead of as request parameter. The first path parameter has an index of0. This takes precedence overnameattribute.- Returns:
- The index of the path parameter.
- Since:
- 2.5
 - Default:
- -1
 
 
- 
 - 
- 
labelString label (Optional) the label used to refer to the parameter.- Returns:
- The label used to refer the parameter, defaults to the nameattribute.
 - Default:
- ""
 
 
- 
 - 
- 
converterString converter (Optional/Required) The converter to be used for converting the parameter to the type that is to be injected. Optional if the target type is String, otherwise required.A converter can be specified in 3 ways: - A string value representing the converter-id as used by Application.createConverter(String)
- An EL expression that resolves to a String representing the converter-id
- An EL expression that resolves to a Converterinstance.
 If this attribute is specified in addition to converterClass(), this attribute takes precedence.- Returns:
- The converter used to convert the parameter to model value.
 - Default:
- ""
 
- A string value representing the converter-id as used by 
 
- 
 - 
- 
requiredboolean required (Optional) Flag indicating if this parameter is required (must be present) or not. The required check is done after conversion and before validation. A value is said to be not present if it turns out to be empty according to the semantics ofUtils.isEmpty(Object).- Returns:
- Whether the absence of the parameter should cause a validation error.
 - Default:
- false
 
 
- 
 - 
- 
validatorsString[] validators (Optional) The validators to be used for validating the (converted) parameter.A validator can be specified in 3 ways: - A string value representing the validator-id as used by Application.createValidator(String)
- An EL expression that resolves to a String representing the validator-id
- An EL expression that resolves to a Validatorinstance.
 If this attribute is specified in addition to validatorClasses()then the validators from both attributes will be added to the final collection of validators. The validators from this attribute will however be called first.- Returns:
- The validators used to validate the (converted) parameter.
 - Default:
- {}
 
- A string value representing the validator-id as used by 
 
- 
 - 
- 
converterClassClass<? extends Converter> converterClass (Optional) Class of the converter to be used for converting the parameter to the type that is to be injected. This is ignored whenconverter()is specified.- Returns:
- The converter class used to convert the parameter to model value.
 - Default:
- jakarta.faces.convert.Converter.class
 
 
- 
 - 
- 
validatorClassesClass<? extends Validator>[] validatorClasses (Optional) Class of one ore more validators to be used for validating the (converted) parameter. These will run after the ones specified invalidators().- Returns:
- The validator classes used to validate the (converted) parameter.
 - Default:
- {}
 
 
- 
 - 
- 
converterAttributesAttribute[] converterAttributes (Optional) Attributes that will be set on the converter instance obtained fromconverter()orconverterClass().For each attribute the converter instance should have a writable JavaBeans property with the same name. The value can be a string literal or an EL expression. String literals are coerced if necessary if there's a PropertyEditoravailable (the JDK provides these for the primitive types and their corresponding boxed types).Attributes for which the converter doesn't have a property (setter) are silently ignored. - Returns:
- The attributes which need to be set on the converter.
 - Default:
- {}
 
 
- 
 - 
- 
validatorAttributesAttribute[] validatorAttributes (Optional) Attributes that will be set on each of the validator instances obtained fromvalidators()andvalidatorClasses().For each attribute the validator instances should have a writable JavaBeans property with the same name. The value can be a string literal or an EL expression. String literals are coerced if necessary if there's a PropertyEditoravailable (the JDK provides these for the primitive types and their corresponding boxed types).Attributes for which any given validator doesn't have a property (setter) are silently ignored. - Returns:
- The attributes which need to be set on the validators.
 - Default:
- {}
 
 
- 
 - 
- 
converterMessageString converterMessage (Optional) A message that will be used if conversion fails instead of the message set by the converter.The value for which conversion failed is available as {0}. The label associated with this parameter value (see thelabel()attribute) is available as{1}.- Returns:
- The error message to be used when the converter()orconverterClass()fail.
 - Default:
- ""
 
 
- 
 - 
- 
validatorMessageString validatorMessage (Optional) A message that will be used if validation fails instead of the message set by the validator(s).The value for which validation failed is available as {0}. The label associated with this parameter value (see thelabel()attribute) is available as{1}.- Returns:
- The error message to be used when any of the validators()orvalidatorClasses()fail.
 - Default:
- ""
 
 
- 
 - 
- 
requiredMessageString requiredMessage (Optional) A message that will be used if a non-empty value is submitted instead of the default message associated with theRequiredValidator.The (empty) value for which the required check failed is available as {0}. (this will be either null or the empty string) The label associated with this parameter value (see thelabel()attribute) is available as{1}.- Returns:
- The error message to be used on empty submit while required()istrue.
 - Default:
- ""
 
 
- 
 - 
- 
globalMessageboolean globalMessage (Optional) Whether to add the faces message as a global message instead of a message for the currentUIViewRoot.- Returns:
- Whether to add the faces message as a global message instead of a message for the current UIViewRoot.
- Since:
- 4.5
 - Default:
- false
 
 
- 
 - 
- 
disableBeanValidationboolean disableBeanValidation (Optional) Flag that disables bean validation for this instance.NOTE: bean validation at the moment (OmniFaces 1.6) is done against the ParamValuethat is injected. In many cases this will be of limited use. We hope to directly inject the converted type in OmniFaces 1.7 and then bean validation will make more sense.If trueno bean validation will be attempted. Iffalse(the default) no specific action is taken, and it will depend on the availability of bean validation and the globalBeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAMEsetting whether bean validation is attempted or not.- Returns:
- Whether to disable bean validation or not.
 - Default:
- false
 
 
- 
 - 
- 
overrideGlobalBeanValidationDisabledboolean overrideGlobalBeanValidationDisabled (Optional) Flag that overrides the globalBeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAMEsetting.If truebean validation will be performed for this instance (given that bean validation is available) despite it globally being disabled. Iffalse(the default) no specific action is taken.- Returns:
- Whether to override that Faces bean validation is globally disabled.
 - Default:
- false
 
 
- 
 
-