繁体   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