For a simpler solution, you just need to add a placeholder for the date with String as the data type to use the filterBy component.
Steps:
Create a new transient property in the model class.
@Transient private String dateForFilter; public String getDateForFilter() { return dateForFilter; } public void setDateForFilter(String dateForFilter) { this.dateForFilter = dateForFilter; }
Create the logic below before returning the data model.
public List<Item> getDataModel() { List<Item> lstItem = serviceClass.loadItem(userid); for (Item item : lstItem) { DateFormat dateFormat = null; Date date = item.getDate; dateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm"); item.setDateForFilter(dateFormat.format(date)); } return lstItem; }
Update your XHTML to use the dateForFilter property.
<p:column filterBy="#{item.dateForFilter}"> <f:facet name="header"> Transaction Date </f:facet> <h:outputText value="#{item.dateForFilter}" /> </p:column>
Note. You can use this only if you are not using a date to update the contents of the model class.
NTN.
source share