Loading...
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.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Complex Form Layout (Columns and Collection<Item> fields)

Dale Wijnand
1 decade ago Jan 11, 2010 4:19pm
Dale Wijnand
1 decade ago Jan 12, 2010 2:46pm
Jens Jansson
1 decade ago Jan 12, 2010 4:06pm
Dale Wijnand
1 decade ago Jan 12, 2010 4:08pm
Jens Jansson
1 decade ago Jan 12, 2010 4:14pm
Dale Wijnand
1 decade ago Jan 12, 2010 4:46pm
Lars Hellström
1 decade ago Feb 11, 2010 3:13pm
Dale Wijnand
1 decade ago Feb 11, 2010 3:19pm
Lars Hellström
1 decade ago Feb 11, 2010 3:43pm

Thanks Dale, when you add fields to the form (that has a gridlayout), how do you specify where in the grid the field should end up?

Nicolas Barbulesco
10 years ago Jan 16, 2013 5:32pm

Lars Hellström: Thanks Dale, when you add fields to the form (that has a gridlayout), how do you specify where in the grid the field should end up?

I have the same question. I have not (yet) found any example of a Vaadin Form with its fields arranged in a GridLayout. An example of that would help me. :-)

Thank you.

Nicolas

Monir Hossain
10 years ago Jan 16, 2013 7:55pm

What I did for similar situation is extend Form and override attachField(). In the attachField() method I can put the field anywhere I wanted.

public class ComplexForm extends Form {
    public Layout myLayout;
    public FormLayout ifYouWantCaptionOnLeft;
    public ComplexForm() {
          myLayout = GridLayout(); //you can choose any layout
          myLayout.addComponent(ifYouWantCaptionOnLeft);
     }

    @Override
    protected void attachField(Object propertyId, Field field) {
         if (propertyId == something) {
              myLayout.addComponent();
         } else if (if you want caption on left of field) {
              ifYouWantCaptionOnLeft.addComponent();

         }
     }

}

Personally, I'm a big fan of CustomLayout but you can use any Layout you want.

EDIT: Forgot to mention few caveats. DO NOT call setLayout in the form and instead of adding the form to a Container, you'll have to first override getLayout() and call that method.

Last updated on Jan, 18th 2013
Nicolas Barbulesco
10 years ago Jan 23, 2013 11:29am

I did not want to overrite attachField, but eventually I did that too. I don't like the awkward succession of if, this is not very performant. Vaadin Forms are good, but they lack a simpler way of attaching fields wherever one wants in a form.

Nicolas

Henri Sara
10 years ago Jan 23, 2013 11:56am

Nicolas Barbulesco: I did not want to overrite attachField, but eventually I did that too. I don't like the awkward succession of if, this is not very performant. Vaadin Forms are good, but they lack a simpler way of attaching fields wherever one wants in a form.

Awkward this is, but for tests that can be performed with "==", the cost is probably in the nanoseconds per invocation at least after JIT has optimized the code.

In general, for a simpler way to manage forms and data binding, take a look at Vaadin 7 FieldGroup or the FormBinder add-on for Vaadin 6. How much they help depend on your use case (how static or dynamic the forms are, ...) but they should at least make the data binding and layout aspects less dependent on each other if not providing more in your case.

Nicolas Barbulesco
10 years ago Jan 24, 2013 2:08pm

Henri Sara:

Awkward this is, but for tests that can be performed with "==", the cost is probably in the nanoseconds per invocation at least after JIT has optimized the code.

I dont make my tests with ==, but rather with .equals and instanceof. Anyway, it is awkward to have a long succession of if, as though the fields were special cases. The fields are just normal cases where the developer wants to control the position.

I hope that future Vaadin will separate more the intelligence on the fields, tightly linked to the Form, and their position.

Nicolas

Henri Sara
10 years ago Jan 24, 2013 2:35pm

Nicolas Barbulesco: I hope that future Vaadin will separate more the intelligence on the fields, tightly linked to the Form, and their position.

That is exactly the role of FieldGroup, which effectively replaces Form in Vaadin 7.

Nicolas Barbulesco
10 years ago Jan 24, 2013 3:08pm

Cool !

Arun Rai
4 years ago Mar 15, 2018 10:28am