setExpandRatio not working

I am using Vaadin 8 with CDI

In my following Code, the setExpandRatio is not working.

public class EmailTopMenu extends CssLayout {

	public EmailTopMenu(EmailService service) {
		
		Button callButton = new Button(i18n.EMAIL_CALL,
				e -> {
				});
		callButton.setIcon(VaadinIcons.CLOUD_DOWNLOAD);
		callButton.addStyleName("icon-align-top");
		...

		addComponents(callButton, ...);
		addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
	}
@SuppressWarnings("serial")
@CDIView(I18n.EMAIL_VIEW)
public class EmailView extends VerticalLayout implements View {

	private EmailTopMenu emailTopMenu;
	private HorizontalSplitPanel emailContent;

	public EmailView() {
		setSizeFull();
	}

	@PostConstruct
	void init() {

		emailTopMenu = new EmailTopMenu(service);
		emailTopMenu.setSizeFull();
		emailContent = new HorizontalSplitPanel();
		emailContent.setSizeFull();

//		setExpandRatio(emailTopMenu, 0.2f);
//		setExpandRatio(emailContent, 0.8f);

		addComponent(emailTopMenu);
		addComponent(emailContent);

	}

I get an error, when i uncomment the 2 lines

setExpandRatio(emailTopMenu, 0.2f);

setExpandRatio(emailContent, 0.8f);

The error i get is:

9:02:59,681 SEVERE [com.vaadin.server.DefaultErrorHandler]
 (default task-6) : org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke void org.app.view.email.EmailView.init() on org.app.view.email.EmailView@1ec4e02b
	at org.jboss.weld.core@3.0.4.Final//org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:85)
	at org.jboss.weld.core@3.0.4.Final//org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:66)
	at org.jboss.weld.core@3.0.4.Final//org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:122)
	at org.jboss.weld.core@3.0.4.Final//org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:162)

Hi

Your problem is very simple. You are trying to apply expand ratio before it is added to layout. You need to add components to layout first. The VerticalLayout in your case throws an exception, which prevents bean manager to complete instantiation of the bean, which in turn is showed as WELD exception.

@PostConstruct
void init() {

	emailTopMenu = new EmailTopMenu(service);
	emailTopMenu.setSizeFull();
	emailContent = new HorizontalSplitPanel();
	emailContent.setSizeFull();

	addComponent(emailTopMenu);
	addComponent(emailContent);

	setExpandRatio(emailTopMenu, 0.2f);
	setExpandRatio(emailContent, 0.8f);

}

Thanks
now it works
2 hours try and error and it is so easy.
Thanks