N
N
Natalia Tsarkevich2014-02-05 02:13:47
Java
Natalia Tsarkevich, 2014-02-05 02:13:47

What does the @FacesConverter annotation do?

Is it possible to know in more detail what this annotation does in java?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BIG_bu, 2014-05-07
@BIG_bu

the converter converts from a string to an object or from an object to a string.
The annotation itself tells the application that this class[OtdelConverter] will be a converter for this class (model) [Otdel].

@FacesConverter(forClass = Otdel.class)
public class OtdelConverter implements Converter { // }

or would be a converter named:
@Override
 public Object getAsObject(FacesContext context, UIComponent component, String value) {
// получаем из базы объект  по входящей строке value ( к примеру по id )
    return otdel; //возвращаем объект отдел
}

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
  //если входящий объект является "отделом" то 
  return ((Otdel) value).getId().toString(); // или что там надо ( name )
}

an example of what can happen in jsf:
get the department id from the url and give the Otdel object to the demandBean controller ( class demandBean { private Otdel otdel; } public Otdel getOtdel/setOtdel)
<f:metadata>
    <f:viewParam name="otdel" value="#{demandBean.otdel}"
                 <!-- если указано имя для @FacesConverter(value= name), то -->
                  converter="otdelConverter" 
                 <!-- иначе можно не указывать конвертер, если он есть - автоматически применится
 converterMessage="#{bundle.badRequest}.#{bundle.unknownOtdel}"
                 />
</f:metadata>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question