[ 
https://issues.apache.org/jira/browse/MYFACES-1695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12519495
 ] 

Mike Kienenberger commented on MYFACES-1695:
--------------------------------------------

Well, that does clear it up.

The problem is that #{1} and #{3 * 1} are of type Long.

Trying to assign a Long to an int primitive (or an Integer) isn't legal.

Assigning a Long to a Number is legal, though.

By default, el represents all numbers as either Long or Double.

Since you're using facelets, you have other options if you REALLY want to use 
int.

Create a "convertNumberToInteger()" facelets static function to convert your 
Longs into an Integer.


> f:setPropertyActionListener and h:commandButton leads to 
> IllegalArgumentException 
> ----------------------------------------------------------------------------------
>
>                 Key: MYFACES-1695
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1695
>             Project: MyFaces Core
>          Issue Type: Bug
>    Affects Versions: 1.2.1-SNAPSHOT
>         Environment: Tomcat 6.0.13, Facelet 1.1.12 / Facelet 1.1.13 snapshot, 
> MyFaces 1.2.1snapshot
>            Reporter: Jan Ziegler
>
> Im having a problem with f:setPropertyActionListener when binding the target 
> to an int-field. I never had this problem when using the latest MyFaces 1.1 
> and Facelets 1.1.12 which backported the 
> setPropertyActionListener-functionality to JSF 1.1 Environments.
> Here´s an excerpt of the example xhtml-page:
> <h:commandButton value="click">
>      <f:setPropertyActionListener target="#{myBean.currentPage}" value="1" />
> </h:commandButton>
> and here the bean (int-approach):
> public class MyBean
> {
>     private int currentPage;
> ...
>       public int getCurrentPage()
>       {
>               return this.currentPage; 
>       }
>       public int setCurrentPage(int page)
>       {
>               this.currentPage = page;
>       }
> ...
> } 
> So when I click on the button to perform a submit I´m getting the following 
> Exception:
> java.lang.IllegalArgumentException: argument type mismatch
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>       at java.lang.reflect.Method.invoke(Unknown Source)
>       at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
>       at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:68)
>       at 
> org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.access$501(FacesCompositeELResolver.java:46)
>       at 
> org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver$6.invoke(FacesCompositeELResolver.java:132)
>       at 
> org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.invoke(FacesCompositeELResolver.java:148)
>       at 
> org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:128)
>       at org.apache.el.parser.AstValue.setValue(AstValue.java:114)
>       at 
> org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:249)
>       at 
> com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:93)
>       at 
> com.sun.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:113)
>       at javax.faces.event.ActionEvent.processListener(ActionEvent.java:48)
>       at 
> javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:487)
>       at javax.faces.component.UICommand.broadcast(UICommand.java:105)
>       at 
> javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:292)
>       at javax.faces.component.UIViewRoot.process(UIViewRoot.java:209)
>       at 
> javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:117)
>       at 
> org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
>       at 
> org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
>       at 
> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
>       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>       at 
> org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>       at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
>       at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
>       at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>       at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
>       at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>       at 
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
>       at 
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
>       at 
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
>       at 
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
>       at java.lang.Thread.run(Unknown Source)
> Afterwards I changed the target-binding to String -this fixed the problem for 
> my xhtml-example above. I change the Methods like this:
> public class MyBean
> {
>     private int currentPage;
> ...
>       public String getCurrentPage()
>       {
>                 return String.valueOf(this.currentPage); 
>       }
>       public void setCurrentPage(String page)
>       {
>                 this.currentPage = Integer.parseInt(page);
>       }
> ...
> } 
> so far so good, but I´m facing another problem, when having 
> "calculated-expression" as the value of setPropertyActionListener like:
> <f:setPropertyActionListener target="#{myBean.currentPage}" 
> value="#{myBean.currentPage - 1}" />
> then neither the int-approach nor the string-approach works. with using the 
> int-binding I´m getting the same error as above and with the string-binding i 
> get another IllegalArgumentException (caused by a ClassCastException):
> java.lang.IllegalArgumentException: [EMAIL PROTECTED]
>       at sun.reflect.GeneratedMethodAccessor188.invoke(Unknown Source)
>       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>       at java.lang.reflect.Method.invoke(Unknown Source)
>       at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
>       at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:68)
>       at 
> org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.access$501(FacesCompositeELResolver.java:46)
>       at 
> org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver$6.invoke(FacesCompositeELResolver.java:132)
>       at 
> org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.invoke(FacesCompositeELResolver.java:148)
>       at 
> org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:128)
>       at org.apache.el.parser.AstValue.setValue(AstValue.java:114)
>       at 
> org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:249)
>       at 
> com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:93)
>       at 
> com.sun.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:113)
>       at javax.faces.event.ActionEvent.processListener(ActionEvent.java:48)
>       at 
> javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:487)
>       at javax.faces.component.UICommand.broadcast(UICommand.java:105)
>       at 
> javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:292)
>       at javax.faces.component.UIViewRoot.process(UIViewRoot.java:209)
>       at 
> javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:117)
>       at 
> org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
>       at 
> org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
>       at 
> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
>       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>       at 
> org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>       at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
>       at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
>       at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>       at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
>       at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>       at 
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
>       at 
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
>       at 
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
>       at 
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
>       at java.lang.Thread.run(Unknown Source)
> I also tried to use standard converters to ensure that "value" is always 
> converted to an Integer or String, e.g.:
> <f:setPropertyActionListener target="#{myBean.currentPage}" value="1" >
>      <f:convertNumber integerOnly="true"/>
> </f:setPropertyActionListener>
> But I also had no luck with this. It didn´t change anything.
> So whats wrong here? Do I have to ensure or convert the value somehow or 
> should the jsf-implementation perform the needed convertions?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to