2 Replies Latest reply on Sep 3, 2012 2:54 AM by mboukayoua

    How to add programmatically a dateFormat or dateConverter to a HtmlOutputText?


      Hi guys!


      I'm trying to  format a date, which it is created at runtime inside a rich:column. So when I create the rich:column and the HtmlOutputText I create a DateTimeConverter in order to give the format I need, but it is not working.

      In xhtml I can do that like this:


      <h:outputText value="#{res.instanceCreateDate}">

           <f:convertDateTime type="date" pattern="dd/MM/yyyy" />



      In Java I'm doing this:


      private void populateDynamicDataTable() {
           // Some code.
           UIColumn column = new UIColumn();
           HtmlOutputText output = new HtmlOutputText();
           output.setValueExpression("value", createValueExpression("#{dynamicItem." + selectedColumns.get(i).getValue() + "}", String.class));
           ... // Some code.
      private DateTimeConverter createDateTimeConverter(String pattern){
           DateTimeConverter dtc = (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
           return dtc;
      private ValueExpression createValueExpression(String valueExpression, Class<?> valueType) {
           FacesContext facesContext = FacesContext.getCurrentInstance();
           return facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), valueExpression, valueType);


      I suppose this should work but is not.


      Does anybody know why is not working? Am I doing wrong or missing something?


      Thanks in advance for any comment.