簡體   English   中英

jsf:將參數傳遞給支持Bean中的方法

[英]jsf: Passing arguments to method in backing bean

我需要將諸如#{bean.userProfile}之類的參數傳遞給備用bean中諸如clear(UserProfile profile)之類的方法。

<a4j:commandButton  value="Cancel" onclick="#{rich:component('id_up')}.hide()"  execute="@this" type="reset" action="#{profilesBean.clear()}" render="id_panel">

我正在尋找在動作中編寫類似這樣的語法:

 action="#{profilesBean.clear(#profilesBean.selectedProfile)}"

我需要通過“ selectedProfile”發送所有userProfile屬性。

如果使用EL2.2,則可以使用與預期非常相似的語法(應刪除第二個#):

action="#{profilesBean.clear(profilesBean.selectedProfile)}"

有幾種方法可以將參數從jsf頁面傳遞到backingBean,我通常使用這種方式:

<h:commandButton action="#{profilesBean.clear}" >
    <f:setPropertyActionListener target="#{profilesBean.selectedProfile}" value="#{profilesBean.userProfile}" />
</h:commandButton>

您可以在mkyong網站中找到其他方式

我更喜歡

<h:commandButton action="#{profilesBean.clear}">
    <f:param name="selectedProfile" value="selectedProfile" />
</h:commandButton>

和腐蝕性豆

 public String clear() {

  Map<String,String> params = 
            FacesContext.getExternalContext().getRequestParameterMap();
  String action = params.get("selectedProfile");
      //...

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM