How to call a method with parameters in JSF

The simplest (and most powerful) way to pass parameters is via JSF method expression which has been introduced in JSF 2.0 and EL 2.2. So this is only possible if you’re running on a Servlet 3.0 / EL 2.2 capable container like Tomcat 7, Glassfish 3, JBoss AS 6, etc and your web.xml is been declared as per Servlet 3.0 specification.

<web-app version="3.0"  xmlns=""      
xsi:schemaLocation="" >    

Here’s an example which passes a static string to the confirm method:

<h:commandButton value="Confirm" action="#{imanager.confirm('name')}" />

 public void confirm(String s) {
  System.out.println("Called with parameter "+s);

Of course you can pass also runtime attributes, for example you could add a button which identifies the row which has been clicked, by passing the “name” element of the model:

<h:dataTable value="#{imanager.cacheList}" var="item">
    <f:facet name="header">Name</f:facet>
    <h:outputText value="#{}" />
    <f:facet name="header">Show</f:facet>
    <h:outputText value="#{}" />
    <f:facet name="header">Action</f:facet>
    <h:commandButton value="Confirm" action="#{imanager.confirm(}" />


Found the article helpful? if so please follow us on Socials