f:viewParam 具有多个值
我有一个
驱动的搜索屏幕。我正在尝试实现它以获取单个
的多个值。
我相信正确的 URL 看起来像
<url>?state=COMPLETE&state=PENDING
XHTML 部分如下所示:
<f:metadata>
<f:viewParam name="state"
value="#{backingBean.state}"
converter="#{stateNameConverter}" />
</f:metadata>
我在 backingBean 上尝试了以下 2 个方法签名:
public void setState(State... state)
希望 JSF 实现能够为值构建一个数组并在支持 bean 上设置。 JSF 实现失败,错误指出无法将枚举转换为枚举数组。
public void setState(State state)
我认为 JSF 实现可能会设置在 URL 中找到的转换后的值。仅设置了第一个值。
stateNameConverter
在 String
和 enum
值之间进行转换。
JSF 2 中的
是否可以有多个值?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,不幸的是,没有
这样的标签。 Mojarra 的UIViewParameter#decode()
实现(这是后面的代码
标记),这证实了:现在解决此问题的最佳方法是自己从
ExternalContext#getRequestParameterValuesMap()
中的中收集值>@PostConstruct
或
或者可能是@ManagedProperty("#{paramValues.state}")
String[]
属性。您还可以创建一个自定义
标记来实现这一点,但这并不完全是微不足道的。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.