since 3 converter tags are associated with 3 components ,3 instances of converters are created and used. This i feel as unnecessary. can we create only one instance of converter and associate it with 3 uicomponents ? this i feel improves the performance .
Are you asking if it is possible to define that a converter is "reusable" or are you asking why it is not implemented the way you described?
I think that making a few extra objects that have a very short lifespan is not such a big deal. And on the other hand since converters can do so much more in the background than just "format a field" (like contact a database or use object properties and so on) it is a much more safer to just recreate the object every time. But this is of course a rare case.
If you do want to use just one object it is possible. Just use the binding attribute in the f:converter tag!
Converters are stateless components. That means that instance variables are not really appropriate and therefore in theory, a single converter instance could be used for all 3 items. In current implementations, however, I believe 3 instances would be created. On the other hand, instantiation is a pretty low-overhead operation in current Java implementations.
If you absolutely, positively MUST have only one converter code instance, make a converter method in a backing bean and use that instead.
However, as we frequently caution people in our optimization forum, premature optimization is not a wise thing to do.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Apr 15, 2008
Tim Holloway wrote:If you absolutely, positively MUST have only one converter code instance, make a converter method in a backing bean and use that instead.
Is that possible? I was under the impression that doing that is only possible with validator. Or did you mean that the backing bean should implement Converter interface?