Hmmm, sounds like conversion may be a little overcomplicated for me right
now...

I'm not using Facelets at the mo, I'm going to try them out after I've got
to grips with JSF, so I think I'll just take the easy option and change the
bean API to use Number.

Thanks again.


Mike Kienenberger wrote:
> 
> Well, the problem is that javax.faces.Integer converts a string to an
> integer.
> You'd need to convert a Long to an integer.
> 
> I haven't actually used a converter on updateActionListener, but I'd
> think a Long to Integer converter should work.
> 
> If you're using facelets, you can write your own functions for doing
> conversion:
> 
> #{myFunctions:convertLongToInt(yourvalue)}
> 
> Realistically, since JSF generates Doubles and Longs, your best bet is
> to make your accessor be of type Number and then convert it in your
> bean code if you want it to be of a particular format.
> 
> Thus, when you have control over the bean api, make your type Number.
> 
> For those cases where  you don't,  you could put a wrapper accessor on
> your bean, either via subclassing or delegating.
> 
> public Number getPageNumber() { return new Integer(getPageNum()); }
> public void setPageNumber(Number number) { setPageNum(number.intValue());
> }
> 
> 
> On 5/31/07, gazlm <[EMAIL PROTECTED]> wrote:
>>
>> Cheers, Mike, that eases my confusion a little. I thought I might have
>> been
>> doing something wrong...
>>
>> Is it possible to convert the EL return value to the right type? The
>> updateActionListener docs state "An optional Converter may be associated
>> with this listener, and if present will be invoked to convert the value
>> to
>> the datatype expected by the target property."
>>
>> I tried using converter="javax.faces.Integer" to force the conversion to
>> an
>> int, but this got me nowhere at all.
>>
>> I'm pretty new to JSF, and I have the feeling I'm barking up the wrong
>> tree
>> - any help appreciated.
>>
>> Cheers,
>>
>>
>> Mike Kienenberger wrote:
>> >
>> >> Is it expected behaviour for an EL arithmetic expression to always
>> return
>> >> a
>> >> Long?
>> >
>> > Yes.  Or a Double if the value cannot be represented as a Long.
>> >
>> >
>> >
>> > On 5/31/07, gazlm <[EMAIL PROTECTED]> wrote:
>> >>
>> >> I have a problem with type conversions when using updateActionListener
>> to
>> >> set
>> >> an int property in a backing bean...
>> >>
>> >> I'm using a bean which has properties pageNum and numPages, and I have
>> >> command links that refresh the page, with an updateActionListener
>> >> changing
>> >> the value of the pageNum property.
>> >>
>> >> If I use the updateActionListener like this:
>> >>
>> >> <t:updateActionListener property="#{bean.pageNum}" value="0" />
>> >>
>> >> then I have no problems, but if I try to do something like this:
>> >>
>> >> <t:updateActionListener property="#{bean.pageNum}"
>> >> value="#{bean.pageNum+1}"
>> >> />
>> >>
>> >> then I get an exception:
>> >>
>> >> javax.faces.el.EvaluationException: Exception setting property
>> helloCount
>> >> of
>> >> base with class demo.GetNameBean, caused by an argument type mismatch.
>> >> The
>> >> full stack trace is attached below.
>> >>
>> >> From debugging through the code while running, it seems that when I do
>> >> any
>> >> arithmetic in a JSF EL expression, the result is a Long, which can't
>> be
>> >> used
>> >> as an argument when the required type is int.
>> >>
>> >> If I change my bean to accept a Long instead of an int, the problem
>> goes
>> >> away, but that doesn't seem ideal to me...
>> >>
>> >> Does anyone else have this problem?
>> >> Is it expected behaviour for an EL arithmetic expression to always
>> return
>> >> a
>> >> Long?
>> >>
>> >> Cheers.
>> >>
>> >> ERROR [[/testMyFaces].[Faces Servlet]:http-8080-Processor25] -
>> >> Servlet.service() for servlet Faces Servlet threw exception
>> >> javax.faces.el.EvaluationException: Exception setting property pageNum
>> of
>> >> base with class com.gaz.Bean
>> >>         at
>> >>
>> org.apache.myfaces.el.PropertyResolverImpl.setValue(PropertyResolverImpl.java:185)
>> >>         at
>> >>
>> org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java:275)
>> >>         at
>> >>
>> org.apache.myfaces.custom.updateactionlistener.UpdateActionListener.processAction(UpdateActionListener.java:156)
>> >>         at
>> >> javax.faces.event.ActionEvent.processListener(ActionEvent.java:48)
>> >>         at
>> >>
>> javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:484)
>> >>         at
>> javax.faces.component.UICommand.broadcast(UICommand.java:75)
>> >>         at
>> >>
>> javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:94)
>> >>         at
>> >>
>> javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:168)
>> >>         at
>> >>
>> org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
>> >>         at
>> >>
>> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
>> >>         at
>> javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
>> >>         at
>> >>
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
>> >>         at
>> >>
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>> >>         at
>> >>
>> org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
>> >>         at
>> >>
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
>> >>         at
>> >>
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>> >>         at
>> >>
>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
>> >>         at
>> >>
>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
>> >>         at
>> >>
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
>> >>         at
>> >>
>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
>> >>         at
>> >>
>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
>> >>         at
>> >>
>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
>> >>         at
>> >>
>> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
>> >>         at
>> >>
>> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
>> >>         at
>> >>
>> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
>> >>         at
>> >>
>> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
>> >>         at
>> >>
>> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
>> >>         at java.lang.Thread.run(Thread.java:595)
>> >> Caused by: javax.faces.el.EvaluationException: Bean: com.gaz.Bean,
>> >> property:
>> >> pageNum
>> >>         at
>> >>
>> org.apache.myfaces.el.PropertyResolverImpl.setProperty(PropertyResolverImpl.java:410)
>> >>         at
>> >>
>> org.apache.myfaces.el.PropertyResolverImpl.setValue(PropertyResolverImpl.java:173)
>> >>         ... 27 more
>> >> Caused by: java.lang.IllegalArgumentException: argument type mismatch
>> >>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> >>         at
>> >>
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> >>         at
>> >>
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> >>         at java.lang.reflect.Method.invoke(Method.java:585)
>> >>         at
>> >>
>> org.apache.myfaces.el.PropertyResolverImpl.setProperty(PropertyResolverImpl.java:406)
>> >>         ... 28 more
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/argument-type-mismatch-when-setting-property-with-updateActionListener-tf3846565.html#a10894017
>> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/argument-type-mismatch-when-setting-property-with-updateActionListener-tf3846565.html#a10894284
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: 
http://www.nabble.com/argument-type-mismatch-when-setting-property-with-updateActionListener-tf3846565.html#a10896824
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Reply via email to