I have a <f:viewParam>
driven search screen. I am trying to implement it to take multiple values for a single <f:viewParam>
.
I believe the correct URL would look something like
<url>?state=COMPLETE&state=PENDING
The XHTML section is as follows:
<f:metadata>
<f:viewParam name="state"
value="#{backingBean.state}"
converter="#{stateNameConverter}" />
</f:metadata>
I have tried the following 2 method signatures on backingBean:
public void setState(State... state)
Was hopeful that JSF implementation would build an array for the values and set on the backing bean. JSF implementation failed with error stating it cannot convert enum to array of enums.
public void setState(State state)
Thought that maybe the JSF implementation would set the converted values as it found them in the URL. Only the first value was set.
The stateNameConverter
converts between String
and enum
value.
Is it possible to have multiple values for <f:viewParam>
in JSF 2?
No, unfortunately, there's no such tag as
<f:viewParams>
. There's also a comment in Mojarra'sUIViewParameter#decode()
implementation (which is the code behind<f:viewParam>
tag) which confirms that:Right now your best bet to workaround this is by gathering the values yourself from
ExternalContext#getRequestParameterValuesMap()
in a@PostConstruct
or<f:viewAction>
or maybe a@ManagedProperty("#{paramValues.state}")
on aString[]
property.You could also create a custom
<my:viewParams>
tag which achieves that, but this isn't exactly trivial.