Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
ReadOnly field in FieldGroup
I just want setReadOnly TextField (for example) in FieldGroup, but the TexField not assume the property read only.
My code:
form = new FormLayout();
fieldGroup = new BeanFieldGroup(User.class);
txtName = new TextField("Nome");
form.addComponent(txtName);
fieldGroup.bind(txtName, User.PROPERTY_NAME);
fieldGroup.setBuffered(true);
txtName.setReadOnly(true);
Someone help me, please?
Hi,
I created the following minimal Vaadin UI to try to reproduce the problem you are experiencing:
@Theme("mytheme")
@Widgetset("com.example.myapplication.MyAppWidgetset")
public class MyUI extends UI {
private FormLayout form;
private BeanFieldGroup<User> fieldGroup;
private TextField txtName;
public class User {
static final String PROPERTY_NAME = "name";
String name;
}
@Override
protected void init(VaadinRequest vaadinRequest) {
form = new FormLayout();
fieldGroup = new BeanFieldGroup<User>(User.class);
txtName = new TextField("Name");
form.addComponent(txtName);
fieldGroup.bind(txtName, User.PROPERTY_NAME);
fieldGroup.setBuffered(true);
txtName.setReadOnly(true);
setContent(form);
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
But I could not reproduce the problem. The TextField is in read only mode in the UI. Maybe I misunderstood your problem?
Jonni Nakari: Hi,
I created the following minimal Vaadin UI to try to reproduce the problem you are experiencing:@Theme("mytheme") @Widgetset("com.example.myapplication.MyAppWidgetset") public class MyUI extends UI { private FormLayout form; private BeanFieldGroup<User> fieldGroup; private TextField txtName; public class User { static final String PROPERTY_NAME = "name"; String name; } @Override protected void init(VaadinRequest vaadinRequest) { form = new FormLayout(); fieldGroup = new BeanFieldGroup<User>(User.class); txtName = new TextField("Name"); form.addComponent(txtName); fieldGroup.bind(txtName, User.PROPERTY_NAME); fieldGroup.setBuffered(true); txtName.setReadOnly(true); setContent(form); } @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true) @VaadinServletConfiguration(ui = MyUI.class, productionMode = false) public static class MyUIServlet extends VaadinServlet { } }
But I could not reproduce the problem. The TextField is in read only mode in the UI. Maybe I misunderstood your problem?
Jonni, You are right. My mistake.
I had a fieldgroup.setItemDataSource after instanciate my object with new BeanFieldGroup<User>(User.class);
Thanks for the reply. Sorry for my silliness.