2

I'm using JSF 2.0 with primefaces over JBoss 7. In some part of the code, I have the following:

public void setItemValue(int value) {
    this.value = value;
}

and in the xhtml:

<p:commandButton ajax="true" value="Button" update="@form" 
action="#{bean.setItemValue(1)}"/>

The problem is, when I click the button, I get an javax.el.MethodNotFoundException, saying that setItemValue(java.lang.Long) doesn't exists. Off course it doesn't, it should be a int or Integer value! Anyone has seen this problem? there is any alternative other than changing my method to receive a long? Thanks!

EDIT: Just downloaded the SNAPSHOT of JBoss 7.2, and it works fine on it. Looks like its a bug of JBoss 7.1.1 :(

Montolide
  • 773
  • 3
  • 12
  • 27
  • 1
    Try with f:setPropertyActionListener or #{bean.setItemValue('1')} – Adrian Mitev Jul 02 '12 at 20:52
  • Second try: `Method not found: bean.setItemValue(java.lang.String)`. But the first try worked! The bad part is that I'm still not able to pass an `Integer` or `int` to a method through jsf, but this is a nice workaround :) – Montolide Jul 03 '12 at 12:37
  • Same with Tomcat 7.0.26. Switching to Tomcat 7.0.28 fixed it for me. I do think that literals in EL are indeed Long but I like the fact that the method with Integer is found as matching in Tomcat 7.0.28. – Milo van der Zee Jul 05 '12 at 08:17

4 Answers4

3

It looks a bit strange, but you can call the method intValue on the Long object self inside EL 2.2

<p:commandButton ... action="#{bean.setItemValue((1).intValue())}"/>
h2mch
  • 521
  • 5
  • 23
1

The method expression type for action is

String action()

So use

 public String setItemValue(Integer value) {
    this.value = value;
    return null;
}

See also:

UPDATE You need to declare the Servlet version as 3.0 to take full advantage of the EL 2.2 such as passing the parameter. For that change your web-app element in your web.xml to this:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       
 xmlns="http://java.sun.com/xml/ns/javaee" 
 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee    
 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"  
 version="3.0">
Community
  • 1
  • 1
Ravi Kadaboina
  • 8,494
  • 3
  • 30
  • 42
  • If you return null, then the current page will be reloaded. If you have one then just return an outcome view. – Ravi Kadaboina Jul 03 '12 at 00:45
  • Thanks for the explanation about the action method signature! Unfortunately, the error persists :( `Method not found: bean.setItemValue(java.lang.Long)` – Montolide Jul 03 '12 at 12:29
  • Hey Ravi, sorry for taking too long. I already use Servlet 3.0, I can pass the parameter OK, but it goes as Long, instead of Integer, that I was expecting. I downloaded JBoss 7.2 SNAPSHOT, and it went well... maybe it is a bug of JBoss 7.1.1 – Montolide Jul 13 '12 at 11:51
1

Don't use get or set prefix in any bean methods (Its a really bad practice) , action attribute expects a method name rather than some getter or setter

get and set are used only for getters and setters of your bean variables

Better replace your setItemValue with something like assignItemValue

like this:

<p:commandButton ajax="true" value="Button" update="@form" 
    action="#{bean.assignItemValue(1)}"/>

where

public void assignItemValue(Long value) { //you could also try with int value...
   //set the value to whenever you want too...
}
Daniel
  • 36,833
  • 10
  • 119
  • 200
0

Apologies for resurrecting this ancient thread. If you are still using Jboss 7.11 or hit similar issues and don't want to go the EL (1).intValue() route, you can also jippo your way around it in your managed bean as follows :-

public String setItemValue(Long longVal) {
    return setItemValue(longVal.intValue());
}
Robin Martin
  • 73
  • 1
  • 5