Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3979652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:11:46+00:00 2026-05-20T05:11:46+00:00

I have a setup where I wan’t to use a FormFieldFactory that returns a

  • 0

I have a setup where I wan’t to use a FormFieldFactory that returns a Form that also has a Form with a FormFieldFactory.

My entities are Subscription that has a name and a collection of Prices. A Price has a country and a price.
I have a Form to present the Subscription, and the FormFieldFactory that is attached returns a TextField for the name, and another Form for the price entities.
The Price entity form returns a table where each Price should be shown as an Item.

My problem is that I can not get this to work. The result is just a page with the Subscription and nothing else. Both the FormFieldFactories are called and a Table is returned in the last, so the expected calls are made.

One thing that puzzles me is that PriceFormFieldFactory.createField() is called twice, first with the property “prices” that contains my collection and second with the property “empty” that contains the value “false”. I would expect this to only be one call, since I only have one Subscription with one Collection.

Could someone enlighten me on this?

Thomas

The code:

import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItem;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.ui.*;

import java.util.ArrayList;
import java.util.Collection;

public class SubscriptionComponent extends CustomComponent {
    private HorizontalLayout mainLayout;

    public SubscriptionComponent() {
        buildMainLayout();
    }

    private void buildMainLayout() {
        mainLayout = new HorizontalLayout();
        mainLayout.setSizeFull();
        mainLayout.setSpacing(true);

        Subscription subscription = createSubscription();

        mainLayout.addComponent(new SubscriptionForm(subscription));
        setCompositionRoot(mainLayout);
    }

    private Subscription createSubscription() {
        Collection<Price> prices = new ArrayList<Price>();
        prices.add(new Price("Elbonia", 1));
        prices.add(new Price("El Honduragua", 2));
        return new Subscription("First subscription", prices);
    }

    public class Subscription {
        private String name;
        private Collection<Price> prices;

        public Subscription(String name, Collection<Price> prices) {
            this.name = name;
            this.prices = prices;
        }

        public String getName() {
            return name;
        }

        public Collection<Price> getPrices() {
            return prices;
        }
    }

    public class SubscriptionForm extends Form {

        public SubscriptionForm(Subscription subscription) {
            setFormFieldFactory(new SubscriptionFormFieldFactory());
            setItemDataSource(new BeanItem<Subscription>(subscription));
        }
    }

    public class SubscriptionFormFieldFactory implements FormFieldFactory {
        @Override
        public Field createField(Item item, Object propertyId, Component uiContext) {
            String pid = (String) propertyId;
            if (pid.equals("name")) {
                return new TextField();
            } else if (pid.equals("prices")) {
                Collection<Price> prices = (Collection<Price>) item.getItemProperty("prices").getValue();
                return new PriceForm(prices);
            }

            return null;
        }
    }

    public class PriceForm extends Form {
        public PriceForm(Collection<Price> prices) {
            setFormFieldFactory(new PriceFormFieldFactory());
            setItemDataSource(new BeanItem<PriceFormItem>(new PriceFormItem(prices)));
        }
    }

    public class PriceFormFieldFactory implements FormFieldFactory {
        @Override
        public Field createField(Item item, Object propertyId, Component uiContext) {
            String pid = (String) propertyId;
            if (pid.equals("prices")) {
                return new PriceTable(new PriceContainer((Collection<Price>) item.getItemProperty("prices").getValue()));
            }
            return null;
        }
    }

    public class PriceFormItem {
        private Collection<Price> prices;

        public PriceFormItem(Collection<Price> prices) {
            this.prices = prices;
        }

        public Collection<Price> getPrices() {
            return prices;
        }
    }

    public enum PriceColumns {
        name("Name"), price("Price");

        private String value;

        PriceColumns(String value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return value;
        }
    }

    public class PriceContainer extends BeanItemContainer<Price> {
        public PriceContainer(Collection<Price> prices) {
            super(Price.class);
            for (Price price : prices) {
                addItem(price);
            }
        }
    }

    public class Price {
        private String country;
        private double price;

        public Price(String name, double price) {
            this.country = name;
            this.price = price;
        }

        public String getCountry() {
            return country;
        }

        public double getPrice() {
            return price;
        }
    }

    public class PriceTable extends Table {
        public PriceTable(PriceContainer countryRatesContainer) {
            setContainerDataSource(countryRatesContainer);

            setColumnCollapsingAllowed(true);
            setColumnReorderingAllowed(true);

            setColumnExpandRatio(PriceColumns.name.name(), .7f);
            setColumnAlignment(PriceColumns.price.name(), ALIGN_CENTER);
        }
    }
}

This has been cross-posted on: http://vaadin.com/forum/-/message_boards/message/302906

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:11:46+00:00Added an answer on May 20, 2026 at 5:11 am

    I have found an answer to my problem – not that I like it, but at least I can now focus on finding another solution.
    It appears that others have tried doing what I want to accomplish and found out that at the moment Vaadin does not do it:

    Nested forms: nested form is not visible

    So for now I will change the plan for the layout and find another way to do what I want.

    Thomas

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have setup svnserve server (1.6.5,plain, without apache) on Fedora. The users, who has
I have setup .htaccess to redirect me.example.com to example.com/fun/index.php. This index.php has a session.
I have setup a simple Oracle external table test that I (alongside a DBA
I have setup some automatic form submission code. Basically when a form is submitted
I have setup a WCF service that i am running on IIS 7 that
I have a J2SE program that I'm moving over to use JPA. The existing
i have setup tinymce in a webpage for users to generate html data that
I have setup a Symfony 2 Data Transformer that will allow the user to
I have setup a application in my IIS7 that uses .NET Framework 4.0 (runned
I have setup a settings bundle and can successfully pull data from that. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.