I have studied programming in JSF
, li that for objects to be transformed into String
it takes a Convert to entity.
Is there a class ready and we adapt our Entities? How does it work?
I have studied programming in JSF
, li that for objects to be transformed into String
it takes a Convert to entity.
Is there a class ready and we adapt our Entities? How does it work?
You can create a class that implements the interface Converter
, in it we can define how the data will be converted, this way you customize this conversion.
By steps:
Create a class that implements the javax.faces.contert.Converter
interface and is annotated with @facesConverter
. A converter is a class that can transform strings
into objetos
and objetos
into strings
, so this class should implement methods getAsObject()
and getAsString()
;
The getAsObject()
method should convert from String
to objeto
, in this case you can throw an exception of type ConverterException
;
The getAsString()
method should convert from objeto
to String
.
Answering your main question, when implementing Converter
you only need to apply conversion logic to methods.