JSF2 动作参数

发布于 2024-09-16 05:37:04 字数 462 浏览 4 评论 0原文

我读过有关通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜光 2024-09-23 05:37:04

是的。要么:

action="#{bean.method(param)}"

或者

<h:commandButton .. >
    <f:setPropertyActionListener
         target="#{bean.targetProperty}" value="#{param}" />
</h:commandbutton>

(并在方法中使用 bean 属性)

Yes. Either:

action="#{bean.method(param)}"

Or

<h:commandButton .. >
    <f:setPropertyActionListener
         target="#{bean.targetProperty}" value="#{param}" />
</h:commandbutton>

(and use the bean property in the method)

葵雨 2024-09-23 05:37:04

你说的是这种形式的参数吗?

<h:commandButton action="#{bean.action(param)}" />

这取决于 EL 的实现。只有 JBoss EL 和 JSP 2.2 EL 能够做到这一点。 此答案中描述了如何安装 JBoss EL。

或者,您也可以只使用 f:paramf:param 过去仅适用于 h:commandLink,但从 JSF 2.0 开始,它也适用于 h:commandButton。例如,

<h:commandButton action="#{bean.action}">
    <f:param name="foo" value="bar" />
</h:commandButton>

使用 @ManagedProperty 将参数设置为托管 bean 属性:

@ManagedProperty("#{param.foo}")
private String foo;

但是,使用此方法,您只能使用标准类型(StringNumber、布尔值)。另一种选择是 f:setPropertyActionListener:

<h:commandButton action="#{bean.action}">
    <f:setPropertyActionListener target="#{bean.foo}" value="#{otherBean.complexObject}" />
</h:commandButton>

也就是说,还有更多方法,但这一切都取决于唯一的功能要求和 bean 范围。也许您根本不需要传递“参数”。

You're talking about parameters in this form?

<h:commandButton action="#{bean.action(param)}" />

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. The f:param used to work with h:commandLink only, but since JSF 2.0 it also works on h:commandButton. E.g.

<h:commandButton action="#{bean.action}">
    <f:param name="foo" value="bar" />
</h:commandButton>

with a @ManagedProperty which sets the parameter as managed bean property:

@ManagedProperty("#{param.foo}")
private String foo;

With this you're however limited to standard types (String, Number, Boolean). An alternative is the f:setPropertyActionListener:

<h:commandButton action="#{bean.action}">
    <f:setPropertyActionListener target="#{bean.foo}" value="#{otherBean.complexObject}" />
</h:commandButton>

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.

夏有森光若流苏 2024-09-23 05:37:04

新规格。 JSF2 允许操作方法接收参数,以便您能够

<h:commandButton action="#{bean.action(otherBean.complexObject)}">

在 ManagedBean 上执行以下操作:

public String action(Object complexObject)

*注意:确保包含“el-impl-2.2.jar”*

The new spec. JSF2 allows that the action method receives a param so you be able to do

<h:commandButton action="#{bean.action(otherBean.complexObject)}">

at the ManagedBean the method will be:

public String action(Object complexObject)

*Note: make sure you include the “el-impl-2.2.jar” *

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文