Form and textfield questions


I am quite new to vaadin and have done a simple form with the formlayout.
With this form I want to add some stuff to a MySQL-database.
I read the “book of vaadin” and it says that in most cases you
want to bind the form to a pojo via the BeanItem-class.
I have done this and when I load the form I get a null-value
in every textfield (because no values is set in the pojo).

What can I do to get the inputPromptText to show instead of
the null-values? Have I done this the right way or is it meant
that I should not bind the form to a BeanItem when I only want
to add stuff to a database, not edit or read data?
If I shouldn’t do it this way, how can I do it?

I’m really happy for a basic explanation about this :slight_smile:
(I also like code examples :wink: )

Thanks in advance!

To display an empty value instead of “null” when the value is null, you can say setNullRepresentation(“”) for your TextField.

If you are using a Form bound to a BeanItem, you can do this in a FormFieldFactory - call the superclass method there and then set the null representation if the returned field is a TextField. There should be examples of this around -
is an old one but might work as is.

Hi! And thanks for the replys!

I found that option too, but I want the textfields to be empty so I can see the setInputPrompt-text for every textfield…
Is that even possible??
If I set the setNullRepresentation to an empty string the textfields just get empty, but the InputPromptText doesn’t show… If I hit backspace in a textfield it shows…

I did a simple test with a TextField without data binding or FormFieldFactory. The following TextField shows the input prompt when added to an application:

TextField tf = new TextField();
tf.setInputPrompt("Input prompt");

Yes, I have tried that too, but isn’t the point that you should bind a BeanItem to a form?
Or is it better to do that only when you are going to update/edit something and not use it when registering new things?

Sorry for the late response. I did not mean that you should not use databinding. The point of the example was that setting setNullRepresentation(“”) && setInputPrompt(“Input prompt”) should show input prompt when value is null.