Flipkart Search

Wednesday 18 June 2014

ADF Custom converter for Input/Output Text

As we have already covered most widely used ADF custom validators , now its time to have some hands on ADF custom converters.

 Let's take simple task of displaying a text in upperCase.
 Here goes the sample code of our class
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

public class UpperCaseConverter implements Converter {
    public UpperCaseConverter() {
        super();
    }
    public String getAsString(FacesContext fc, UIComponent uIComponent, Object  obj) {

    return obj.toString().toUpperCase();

    }

    public Object getAsObject(FacesContext fc, UIComponent uIComponent, String string) {

    return string.toString().toUpperCase();

    }

    }
Now we will register this class in our faces-config.xml in the converters section.
And we can apply this converter simply by giving its ID.

  <af:inputText value="#{row.bindings.FirstName.inputValue}"
                                label="#{bindings.EmployeesView1.hints.FirstName.label}"
                                required="#{bindings.EmployeesView1.hints.FirstName.mandatory}"
                                columns="#{bindings.EmployeesView1.hints.FirstName.displayWidth}"
                                maximumLength="#{bindings.EmployeesView1.hints.FirstName.precision}"
                                shortDesc="#{bindings.EmployeesView1.hints.FirstName.tooltip}"
                                id="it3" converter="UpperCase"/>       
           

No comments:

Post a Comment