JSF action method with variable parameter

24,211

Solution 1

If you are using EL 2.2+, it's possible.

If you are using older version ot EL, you can use do the following:

<h:commandButton value="Send" action="#{myBean.checkPIN}" />
   <f:param name="parameter" value="123" />
</h:commandButton>

In the managed bean you can retrieve it like:

public void checkPIN() {
   ...
   Map<String, String> parameterMap = (Map<String, String>) externalContext.getRequestParameterMap();
   String param = parameterMap.get("parameter");
   ...
}

Solution 2

Yes it is possible if you are using > EL 2.2 which is part of Servlet 3.0.

See @BalusC's suggetions here Invoke direct methods or methods with arguments / variables / parameters in EL

Share:
24,211
Mateusz Gaweł
Author by

Mateusz Gaweł

Updated on May 11, 2020

Comments

  • Mateusz Gaweł
    Mateusz Gaweł about 4 years

    How do I call method with variable parameters in JSF?

    I tried something like this:

    <h:commandButton value="Send" action="#{myBean.checkPIN(someOtherBean.PIN)}" />
    

    However, this doesn't work.

  • Mateusz Gaweł
    Mateusz Gaweł about 11 years
    it worked.It must be something wrong with the version. 2.2+ is much clearer to use. Thanks
  • Mateusz Gaweł
    Mateusz Gaweł about 11 years
    you are right. Thank you
  • Suresh Atta
    Suresh Atta about 11 years
    @MateuszGaweł Glad to help you.Mark it as answer if its helpful(tick mark left side).
  • Luiggi Mendoza
    Luiggi Mendoza about 11 years
    @MateuszGaweł looks like the problem is in your web application server. Which one are you using?
  • BalusC
    BalusC about 11 years
    The feature is not specific to JSF 2.x. It's specific to EL 2.2. So using JSF 2.x does in no way imply that EL 2.2 also been used. Carefully read the last paragraph of stackoverflow.com/a/3284328
  • Rodrigo Sasaki
    Rodrigo Sasaki about 11 years
    I know @BalusC. I have carefully read your answer (which was very enlightning btw), and it has that's why I said in the answer things like: "probably" and "even though it might not be the case"