This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

f:converter binding can't bind to a converter instance  RSS feed

 
Ranch Hand
Posts: 1709
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,





I got an error:


javax.faces.view.facelets.TagException: /index1.xhtml @15,60 <f:converter> Default behavior invoked of requiring a converter-id passed in the constructor, must override ConvertHandler(ConverterConfig)


But according to the specification, binding is a value expression referred to a Converter instance.  But why this error occurs?

 
Bartender
Posts: 20107
101
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are binding to a backing bean property, but for Converter, the "binding" attribute must reference an object that implements Converter. That is, a backing bean can construct a Converter object and return it via a property "get" method (that the binding references) or you can reference a Converter class by its id (which is more common) and let JSF instantiate it. To assign a logical ID to a converter, use faces-config.xml or the @FacesConverter class annotation

The binding is a read-only property, so there's no need for a "set" method. It will never be used. Because your backing bean did not instantiate the converter, the binding "get" method would return null.
 
Himai Minh
Ranch Hand
Posts: 1709
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Tim. Thanks for suggesting me to instantiate the MyConverter.
But I found an example here https://memorynotfound.com/binding-converters-to-a-managed-beans-property/,
In this example,
index.xhtml


In this example, the NumberConverter is not instantiated. But it works on my machine.
 
Tim Holloway
Bartender
Posts: 20107
101
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently the "set" method can get called then. The JSF javadocs are really bad about stuff like that.

NumberConverter is a built-in converter, so it gets registered internally. You did not register your converter, so JSF had no way to automatically identify it and instantiate it. JSF cannot simply (or at least efficiently) scan every class in the classloader chain to find classes that are Converters. That's why the annotation or faces-config hint is needed. Plus they map a portable and abstract converter identifier to a specific class.

There are several things that I don't like about that example, though. First, other than the fact that the bean property is actually named and typed as "numberConverter" I see no way for JSF to be able to tell which converter to inject.

Secondly, the backing bean is RequestScoped, which is extremely perilous at the best of times and even more so considering that it's attempting to maintain a stateful variable (amount).
 
Himai Minh
Ranch Hand
Posts: 1709
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I checked, javax.faces.convert.Converter is an interface. So, it won't be instantiated. That is why it does not work.
But javax.faces.converter.NumberConverter is a class, so the memorynotfound example works.
 
Tim Holloway
Bartender
Posts: 20107
101
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Himai Minh wrote:As I checked, javax.faces.convert.Converter is an interface. So, it won't be instantiated. That is why it does not work.
But javax.faces.converter.NumberConverter is a class, so the memorynotfound example works.



There's more to it than that.

MyConverter is a class, but you'll recall that no MyConverter was instantiated.
 
Tim Holloway
Bartender
Posts: 20107
101
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Incidentally, if you're interested in how JBoss implemented the NumberConverter, the source code for its JSF version 2.0 implementation is here:

http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.jboss.spec.javax.faces/jboss-jsf-api_2.0_spec/1.0.0.Beta1/javax/faces/convert/NumberConverter.java

It does not register itself with a FacesConverter annotation, but I'd take it as a given that since it's a JSF built-in, that the JSF initialization code deals with that as a matter of course.
 
Why is the word "abbreviation" so long? And this ad is so short?
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!