我已经阅读了有关通过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>
Run Code Online (Sandbox Code Playgroud)
那么现在谁值得绿色蜱?:-P我可以给他们两个吗?
Boz*_*zho 13
是.或者:
action="#{bean.method(param)}"
Run Code Online (Sandbox Code Playgroud)
要么
<h:commandButton .. >
<f:setPropertyActionListener
target="#{bean.targetProperty}" value="#{param}" />
</h:commandbutton>
Run Code Online (Sandbox Code Playgroud)
(并在方法中使用bean属性)
Bal*_*usC 13
你在谈论这种形式的参数?
<h:commandButton action="#{bean.action(param)}" />
Run Code Online (Sandbox Code Playgroud)
这取决于EL实现.只有JBoss EL和JSP 2.2 EL能够做到这一点.本答案中描述了如何安装JBoss EL .
或者,您也可以使用f:param.在f:param曾经工作h:commandLink而已,但因为JSF 2.0它也适用于h:commandButton.例如
<h:commandButton action="#{bean.action}">
<f:param name="foo" value="bar" />
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)
使用a @ManagedProperty将参数设置为托管bean属性:
@ManagedProperty("#{param.foo}")
private String foo;
Run Code Online (Sandbox Code Playgroud)
有了这个你不过仅限于标准型(String,Number,Boolean).另一种选择是f:setPropertyActionListener:
<h:commandButton action="#{bean.action}">
<f:setPropertyActionListener target="#{bean.foo}" value="#{otherBean.complexObject}" />
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)
也就是说,还有更多方法,但这完全取决于唯一的功能要求和bean范围.毕竟你可能根本不需要传递"参数".
| 归档时间: |
|
| 查看次数: |
23652 次 |
| 最近记录: |