When I make the table non editable, only String components become non editable, while DateField and Select stay editable. How can I make them not editable?
Thank you, Francesco
How about using Date instead of DateField as container properties? That way the table will show the date when table is setEditable(false) and automatically change it to a DateField when you call table.setEditable(true);
Example:
package com.example.playground;
import java.util.Date;
import com.vaadin.Application;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
public class PlaygroundApplication extends Application {
private static final long serialVersionUID = 6031735832707957247L;
@Override
public void init() {
VerticalLayout mainLayout = new VerticalLayout();
mainLayout.setSpacing(true);
Window mainWindow = new Window("Playground Application", mainLayout);
Label label = new Label("Hello Vaadin user");
mainWindow.addComponent(label);
setMainWindow(mainWindow);
IndexedContainer container = new IndexedContainer();
container.addContainerProperty("one", String.class, null);
container.addContainerProperty("two", Date.class, null);
Item item = container.addItem("1");
Item item2 = container.addItem("2");
item.getItemProperty("one").setValue("foo");
item2.getItemProperty("one").setValue("foo2");
Date date = new Date();
Date date2 = new Date();
item.getItemProperty("two").setValue(date);
item2.getItemProperty("two").setValue(date2);
final Table table = new Table("foo", container);
mainWindow.addComponent(table);
mainWindow.addComponent(new Button("click", new ClickListener() {
private static final long serialVersionUID = -8648939862617861344L;
@Override
public void buttonClick(ClickEvent event) {
table.setEditable(!table.isEditable());
}
}));
}
}
Solved: I extended DefaultFieldFactory and in the createField method I return a Select Field. In this way setEditable automatically change components in editable or non editable mode.
Great framework!
Thank you, Francesco