Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date Format as "MM-dd-yyy" in <p:datatable> with dynamic column

I'm having a datatable with dynamic columns generated. i have a date column to be displayed, but in a specific format

in my datatable without dynamic columns generation ... i make the date to display in the specific format by this way

<p:dataTable .....>
  <p:column headerText="Date" id="dateID"
                        sortBy="#{iterator.updatedDate}"
                        filterBy="#{iterator.updatedDate}">

                        <h:outputText value="#{iterator.updatedDate}">
                            <f:convertDateTime pattern="MM-dd-yyyy" />
                        </h:outputText>

  </p:column>
</p:dataTable>

what could i do for getting the same outcome in my datatable with dynamic columns...

can any help me in fixing this...

like image 456
senthil_sss Avatar asked Dec 12 '22 16:12

senthil_sss


2 Answers

If your property is a Calendar type insert .time after it.

<h:outputText value="#{iterator.updatedDate.time}">
       <f:convertDateTime pattern="MM-dd-yyyy" />
 </h:outputText>
like image 118
Talles Penini Avatar answered Jan 19 '23 17:01

Talles Penini


You could create accessor methods in your backing bean that enable you to directly get the Date in the desired format, as a String.

Take this example:

public class MyBean{

    private Date myDate;

    public Date getMyDate() {
        return myDate;
    }

    public String getMyFormattedDate() {
        return new SimpleDateFormat("dd-MM-yyyy").format(myDate);
    }
}

Then, in your dataTable, the property "myFormattedDate" should be called, so the formatted Date gets printed.

like image 41
floshton Avatar answered Jan 19 '23 19:01

floshton