Hello!
I want to describe my problem by a small example.
I have a class “Termine” which represents events. The object has the following characteristics:
private static final long serialVersionUID = -346851073098044440L;
private int terminId;
private Date creationDate;
private Date lastChangeDate;
private Date startDate;
private String startTime;
private Date endDate;
private String endTime;
private String title;
private String description;
private String author;
private Boolean setVisible;
private Kategorie kategorie;
The last value is another class which represents a list of categories, this class has the following variables:
private int categoryId;
private Date creationDate;
private Date changeDate;
private String name;
private String description;
private String author;
The association between the two classes is a 1:n means one “Termin” can only have one category, and is unidirectional.
To display the dates in a table I have created the following container class:
public class TermineContainer extends BeanItemContainer<Termin> {
private static final long serialVersionUID = -7591445585588980941L;
private static Logger log = Logger.getLogger(TermineContainer.class);
// natural order
public static Object[] NATURAL_COL_ORDER;
// Human Readable order
public static String[] COL_HEADERS;
public TermineContainer() throws InstantiationException, IllegalAccessException {
super(Termin.class);
// natural order
NATURAL_COL_ORDER = new Object[] {"startDate", "startTime", "endDate", "endTime", "title", "description", "setVisible", "kategorie", "author"};
// Human Readable order
COL_HEADERS = new String[] {"Start date", "Start time", "End Date", "End time", "Title", "Description", "Is visible", "kategorie", "Author" };
}
/**
* This method returns a list with all Termine
* @param termine
* @return
*/
public static TermineContainer getTermineList(List<Termin> termine){
try {
TermineContainer cont = new TermineContainer();
for(int i = 0; i<termine.size(); i++){
cont.addItem(termine.get(i));
}
return cont;
}
catch(Exception e){
log.error(e.getMessage());
return null;
}
}
}
In my view class I set the data source in the following way in which termineTable represents a table:
/**
* This method updates the table with the current records from the database
*/
private void updateTermineTable(){
termine = TerminRepository.getTerminList("startDate", false);
termineTable.setContainerDataSource(TermineContainer.getTermineList(termine));
termineTable.setVisibleColumns(TermineContainer.NATURAL_COL_ORDER);
termineTable.setColumnHeaders(TermineContainer.COL_HEADERS);
// disable the edit mode
termineTable.setEditable(false);
// enable the selectable mode
termineTable.setSelectable(true);
}
Now if I change the termineTable to termineTable.setEditable(true) the system automatically change the date field to a PopUpdateDateField which is relly fantastic. The other fields are also displayed in the right way except the field where I want to select the category. There is only an empty text field but I want a dropdown menu where I can select the appropriate category.
How can I realize this. Do I really have to change the table creation from container to the described way in the
Vaadin book
. And if this is the only way how can I create a dropdown menu in the table.
I would be very happy if someone would help me!
Thanks Florian