1

I'm trying to invoke bean method from JSF command button, but I keep getting an error

javax.faces.FacesException: wrong number of arguments

This is the code in my page:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:dmx="http://java.sun.com/jsf/composite/dmx"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <head>
        <title>TODO supply a title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    </head>
    <body>
        <ui:composition>
        <h:form>
        <div id="child"></div>
        <h:panelGroup>
            <h:outputText value="Hello, DEMUX JSF!" 
                style="color: #{dmxAdapter.model.get('testData') ? 'green' : 'red' }" />
            <h:commandButton value="Click me" 
                action="#{dmxAdapter.invokeController('com.vektorsoft.demux.samples.hello.HelloController')}"  />
        </h:panelGroup>
        </h:form>
        </ui:composition>
    </body>
</html>

If I change action attribute to call method without parameters, everything works fine. I'm running this in Jetty inside OSGI container. JSF version is Mojarra 2.2.6 and EL 3.0.

I've read multiple answers mentioning that EL 2.2 and above is required for this to work,a nd I think EL 3.0 should work also. This is added as Maven dependency:

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.el</artifactId>
    <version>3.0.0</version>
</dependency>

Can anybody shed any light on what might be wrong here?

Aritz
  • 30,971
  • 16
  • 136
  • 217
vdjurovic
  • 178
  • 2
  • 13
  • It depends on the Jetty version you're dealing with. If not Servlet 3.0 compatible, it's not enough to include the el dependency, you have to override the one being used in your web.xml: http://stackoverflow.com/questions/2333605/using-el-2-2-with-tomcat-6-0-24 Also you don't tell us about your `dmxAdapter.invokeController` method. What's its signature? – Aritz Jul 01 '14 at 11:05
  • Jetty version is 9.2.0.M1. In web.xml, web-app is declared as version 3.1, with context params: com.sun.faces.expressionFactory com.sun.el.ExpressionFactoryImpl Method signature is public void invokeController(String controllerId, Object... args) – vdjurovic Jul 01 '14 at 11:26

1 Answers1

1

As the signature of your method (public void invokeController(String controllerId, Object... args)) says, you've got varargs in your method, which is not supported by EL.

Your servlet container is EL 3.0 compatible, so there's no problem in passing arguments from the view. However you'll need to change your method's signature to make it fully compatible.

See also:

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217