Converter JSF Component

I have a JSF composite component TimePicker.xhtmlwith a base component timePickerComponentthat is used below:

      <mi:timePicker style="display: initial;"
        widgetVar="toTimepickerWidget"
        converter="#{timePickerConverter}"
                            value="#{calendarBean.event.to}" 
      /> 

And timePickerConverteris created in the usual way:

public class TimePickerConverter implements Converter, Serializable {
    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)
            throws ConverterException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2)
            throws ConverterException {
        // TODO Auto-generated method stub
        return null;
    }
}

How to use this converter in a composite component?

UPDATE:

This is the component code:

<cc:implementation componentType="timePickerComponent">
    <h:outputScript name="js/timepicker/timepicker_helper.js" target="head"/>
    <div id="#{cc.clientId}" style="#{cc.attrs.style}">

            <p:inputText id="timepicker"
                    scrollHeight="200"
                    value="#{cc.timeLocal}"  
                    size="5"/>

    </div>
</cc:implementation>

Basically I want to convert plain text from inputTextto Datean object. The part date does not matter to me, I only need the part time of the object. Btw, as a workaround, I will use getConvertedValue, as described in this article, from BalusC A component component with several input fields But I would like to know how to delegate this function to an external converter, as described in the article

, JSF-

+4
1

, backing getConvertedValue. converter:

@FacesComponent("timePickerComponent")
public class TimePickerComponent extends UIInput implements NamingContainer {

    ...

    @Override
    public Object getSubmittedValue() {
        UIInput hourComp = (UIInput) findComponent("timepicker_hour");
        UIInput minutesComp = (UIInput) findComponent("timepicker_minutes");
        return hourComp.getSubmittedValue() + ":" + minutesComp.getSubmittedValue();
    }

    @Override
    protected Object getConvertedValue(FacesContext context,
            Object newSubmittedValue) throws ConverterException {
        Converter converter = (Converter) getAttributes().get("converter");
        if (converter != null) {
            return converter.getAsObject(context, this, (String) newSubmittedValue);
        } else {
            return newSubmittedValue;
        }
    }

}

. : https://github.com/destin/SO-answers/tree/master/SO-composite-jsf-component-with-converter

, JSF String. , . (, : hourComp.getSubmittedValue() + ":" + minutesComp.getSubmittedValue()).

, , , TimeConverters JSF. (, Time). , .

+4

All Articles