format date of a table-column which is bounded to EJB

private BeanItemContainer container;
container = new BeanItemContainer(Supervisors.class);

final Table table = new Table()
    {
        @Override
        protected String formatPropertyValue(Object rowId,
        Object colId, Property property) {
        // Format by property type
        if (property.getType() == Date.class) {
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        [color=#f607e6]

return df.format((Date)property.getValue());
[/color]
}

    return super.formatPropertyValue(rowId, colId, property);
}
    };

    table.setContainerDataSource(container);
table.setVisibleColumns(new Object[]{"fname", "lname", "nickname","gender","dob","telephone", "semail", "fax"});
table.setColumnHeaders(new String[]{ "First Name", "Last Name", "Nickname","Gender","Date of Birth","Telephone", "Email", "Fax"});

try {
	Collection<Supervisors> competences = supervisorBean.findAll();
	for (Supervisors c : competences) {
		container.addBean(c);
	}
} catch (EJBAccessException e) {
	getApplication().getMainWindow().showNotification("Access Denied",
		Window.Notification.TYPE_WARNING_MESSAGE);
} catch (Exception e) {
	getApplication().getMainWindow().showNotification(e.toString(),
				Window.Notification.TYPE_ERROR_MESSAGE);
}
    
    table.setSizeFull();
table.setSelectable(true);
table.setImmediate(true);
layout.addComponent(table);

//------------------------------------------------------------------------------------------------------------------------------------------------------//



Question: I got an error as below:

. The error is on the pink highlighted line above. I do hope someone can take me out of this problem. thank in advance!

SEVERE: java.lang.NullPointerException
at java.util.Calendar.setTime(Calendar.java:1076)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:875)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:868)
at java.text.DateFormat.format(DateFormat.java:316)
at suricate.web.SupervisorView$2.formatPropertyValue(SupervisorView.java:83)

did you check if property.getValue() actually returns a value and not simply null?

Thanks for your reply. I have solved it. :slight_smile: