vplusplus
vplusplus

Reputation: 603

jsf: Passing arguments to method in backing bean

I need to pass an argument like #{bean.userProfile} to a method like clear(UserProfile profile) in the backing bean.

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

I'm looking for the syntax for writing something like this in the action:

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

I need to send all userProfile attributes via "selectedProfile".

Upvotes: 0

Views: 4015

Answers (3)

Vasil Lukach
Vasil Lukach

Reputation: 3728

If you use EL2.2 then you can use very similar syntax as you expected (second # should be removed):

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

Upvotes: 1

Sai prateek
Sai prateek

Reputation: 11896

I prefer

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

and corrosponding bean

 public String clear() {

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

}

Upvotes: 0

nacadev
nacadev

Reputation: 81

there are several ways to pass parameter from jsf page to backingBean, i usually use this way:

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

you can find the other ways in mkyong site

Upvotes: 0

Related Questions