[英]JSF2 Action parameter
我已經閱讀了有關通過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我可以給他們兩個嗎?
是。 或者:
action="#{bean.method(param)}"
要么
<h:commandButton .. >
<f:setPropertyActionListener
target="#{bean.targetProperty}" value="#{param}" />
</h:commandbutton>
(並在方法中使用bean屬性)
你在談論這種形式的參數?
<h:commandButton action="#{bean.action(param)}" />
這取決於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>
使用@ManagedProperty
將參數設置為托管bean屬性:
@ManagedProperty("#{param.foo}")
private String foo;
但是,您只能使用標准類型( String
, Number
, Boolean
)。 另一種方法是f:setPropertyActionListener
:
<h:commandButton action="#{bean.action}">
<f:setPropertyActionListener target="#{bean.foo}" value="#{otherBean.complexObject}" />
</h:commandButton>
也就是說,還有更多方法,但這完全取決於唯一的功能要求和bean范圍。 畢竟你可能根本不需要傳遞“參數”。
新規范。 JSF2允許action方法接收一個param,這樣你就能做到
<h:commandButton action="#{bean.action(otherBean.complexObject)}">
在ManagedBean中,方法將是:
public String action(Object complexObject)
* 注意:請確保包含“el-impl-2.2.jar”*
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.