JSF2 动作参数
我读过有关通过 actionListener 将参数从 jsf 页面传递到 ManagedBean 的内容。是否也可以将参数传递给简单的操作方法?
感谢您的阅读...
谢谢你们的建议!没有你我会迷路:-)
以下对我有用:
<h:commandLink id="link" action="#{overviewController.showDetails}" >
<f:setPropertyActionListener target="#{overviewController.show_id}" value="#{project.id}" />
<h:outputText value="#{project.title}" />
</h:commandLink>
那么现在谁应该得到绿色勾号呢? :-P 我可以给两个吗?
I have read about passing parameters from jsf page to managedbean through actionListener. Is it also possible to pass a parameter to a simple action method?
Thank you for reading...
Thank you both for your advices! I would be lost without you :-)
Following worked for me:
<h:commandLink id="link" action="#{overviewController.showDetails}" >
<f:setPropertyActionListener target="#{overviewController.show_id}" value="#{project.id}" />
<h:outputText value="#{project.title}" />
</h:commandLink>
So now who deserves the green tick? :-P can I give two of them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。要么:
或者
(并在方法中使用 bean 属性)
Yes. Either:
Or
(and use the bean property in the method)
你说的是这种形式的参数吗?
这取决于 EL 的实现。只有 JBoss EL 和 JSP 2.2 EL 能够做到这一点。 此答案中描述了如何安装 JBoss EL。
或者,您也可以只使用
f:param
。f:param
过去仅适用于h:commandLink
,但从 JSF 2.0 开始,它也适用于h:commandButton
。例如,使用
@ManagedProperty
将参数设置为托管 bean 属性:但是,使用此方法,您只能使用标准类型(
String
、Number
、布尔值)。另一种选择是 f:setPropertyActionListener:也就是说,还有更多方法,但这一切都取决于唯一的功能要求和 bean 范围。也许您根本不需要传递“参数”。
You're talking about parameters in this form?
That depends on the EL implementation. Only JBoss EL and JSP 2.2 EL is capable of doing this. How to install JBoss EL is described in this answer.
Alternatively, you can also just use
f:param
. Thef:param
used to work withh:commandLink
only, but since JSF 2.0 it also works onh:commandButton
. E.g.with a
@ManagedProperty
which sets the parameter as managed bean property:With this you're however limited to standard types (
String
,Number
,Boolean
). An alternative is thef:setPropertyActionListener
:That said, there are more ways as well, but this all depends on the sole functional requirement and the bean scopes. Probably you don't need to pass a "parameter" at all after all.
新规格。 JSF2 允许操作方法接收参数,以便您能够
在 ManagedBean 上执行以下操作:
*注意:确保包含“el-impl-2.2.jar”*
The new spec. JSF2 allows that the action method receives a param so you be able to do
at the ManagedBean the method will be:
*Note: make sure you include the “el-impl-2.2.jar” *