Vaadin 8 Binder not populated value in RichTextArea component

Hello,
It’s my first time in forum, so hello everybody. Iban, from Spain.

I’m migrating an application from Vaadin 7 to 8 and I’m having problems populating a value in a RichTextArea component using the Vaadin 8 Binder.

For testing purpose, I’ve tried the same adding a TextField and in this component it works perfectly. It shows the data… I think I’m missing something…
Using BeanFieldGroup from Vaadin 7 worked perfectly

Code from Vaadin 7

	@PropertyId("textValue")
	@Getter private RichTextArea richTextArea = new RichTextArea();
	
	private BeanFieldGroup<WorkProjectValuesEntity> binder = new BeanFieldGroup<WorkProjectValuesEntity>(WorkProjectValuesEntity.class);
	
	private WorkProjectValuesEntity entity;
	
	public RichTextAreaFieldModule(){}
	
	
	@Override
	public Component create(WorkProjectModulesEntity moduleItem) {
		this.moduleItem = moduleItem;
		getWorkProjectValuesEntity();		
		binder.setItemDataSource(entity);
		binder.bind(richTextArea, "textValue");
		
		//Add the component and other stuff...

Code from Vaadin 8

	@Getter private RichTextArea richTextArea = new RichTextArea();
	
	private TextField textField = new TextField();
	
	private Binder<WorkProjectValuesEntity> binder = new Binder<WorkProjectValuesEntity>(WorkProjectValuesEntity.class);
	
	private WorkProjectValuesEntity entity;
	
	public RichTextAreaFieldModule(){}
	
	
	@Override
	public Component create(WorkProjectModulesEntity moduleItem) {
		this.moduleItem = moduleItem;		
		
		getWorkProjectValuesEntity();	//Retrieve values for WorkProjectValuesEntity
		
		binder.forField(richTextArea)	
			  .bind(WorkProjectValuesEntity::getTextValue, WorkProjectValuesEntity::setTextValue);
		
		//For testing purpose
		binder.forField(textField)
			.bind(WorkProjectValuesEntity::getTextValue, WorkProjectValuesEntity::setTextValue);		
		
		binder.readBean(entity);
		
		//Add the component and other stuff...

Am I doing something wrong or is there any problem between the Binder and the RichTextArea component??

Attach an image → https://imageshack.com/a/img924/958/9sXJVr.png

Thanks in advance!!

17312966.png

Are you using Lombok there? Can you try without it?

Yes, I’m using Lombok in both, bean and Component.

I will try without it and let you know.

Thanks!

Hi!

I’ve rid of lombok annotations from both, bean and component, and still doesn’t work.

For testing, I’ve created a dummy project with a bean with lombok annotations and added a RichTextArea component to the UI and it works.

So going deeper into the project:

My project create dinamically tabs. Within those tabs I create Accordions components and within them Custom components. These custom components can be UploadFile, RichTextAreas… it depends (attached an image).

For building the components I use a Strategy Pattern… and basically what it does is:

public class ModuleAccordion extends Accordion {

	@Getter @Setter private WorkProjectModulesEntity module;
	
	public ModuleAccordion() {
		setSizeFull();
	}
	
	public void addItem(WorkProjectModulesEntity moduleItem) throws ReflectiveOperationException{
		
		FieldModuleCreatorContext context = getModuleContext(fieldType);
		
		if(context != null){
			//Here is where I create the component. In this case a RichTextAreaFieldModule
			Component fieldModuleComponent = context.createComponent(moduleItem);
			fieldContainer.addComponent(fieldModuleComponent);
			fieldContainer.setExpandRatio(fieldModuleComponent, 1.0f);

And the RichTextAreaFieldModule code:

public class RichTextAreaFieldModule extends CustomComponent implements FieldModuleComponentCreator, FieldModuleComponentTranslator {
	
	private VerticalLayout rootLayout = new VerticalLayout();
	@Getter private WorkProjectModulesEntity moduleItem;
	
	//Now without Lombok
	private RichTextArea richTextArea = new RichTextArea();
	
	private Binder<WorkProjectValuesEntity> binder = new Binder<WorkProjectValuesEntity>(WorkProjectValuesEntity.class);
	
	private WorkProjectValuesEntity entity;
	
	
	public RichTextAreaFieldModule(){}
	
	
	@Override
	public Component create(WorkProjectModulesEntity moduleItem) {
		this.moduleItem = moduleItem;		
		
		//Here is where I fetch the RichTextArea value
		getWorkProjectValuesEntity();	
		
		binder.forField(richTextArea)	
			  .bind(WorkProjectValuesEntity::getTextValue, WorkProjectValuesEntity::setTextValue);
		
		binder.readBean(entity);
		
		this.buildComponent();		
		
		Responsive.makeResponsive(this);		
		setCompositionRoot(rootLayout);		
		rootLayout.setSizeFull();
		setSizeFull();
		
		return this;

	}

Thanks

17314732.png

I did this dummy test project that seems to be working:

 */
@Theme("mytheme")
public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();

        RichTextArea rta = new RichTextArea();
        Bean bean = new Bean();
        bean.setName("dasda");

        Binder<Bean> binder = new Binder<>(Bean.class);

        binder.bind(rta, Bean::getName, Bean::setName);
        binder.readBean(bean);

        layout.addComponent(rta);

        Button button = new Button("check Bean status", e -> {
            try {
                binder.writeBean(bean);
            } catch (Exception ex) {
                Notification.show("Oh no, error:" + ex);
            }
            Notification.show("Current bean name: " + bean.getName());
        });
        layout.addComponent(button);
        setContent(layout);
    }

    public static class Bean {
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
}```

I have reproduced the problem:

package com.example.binder.test;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Accordion;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

/**
 * This UI is the application entry point. A UI may either represent a browser window 
 * (or tab) or some part of an HTML page where a Vaadin application is embedded.
 * <p>
 * The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be 
 * overridden to add component to the user interface and initialize non-component functionality.
 */
@Theme("mytheme")
public class MyUI extends UI {

	
	String[] tabs = {"Mercury", "Venus", "Earth", "Mars"};
	String[] accordions = {"Apollo I", "Apollo XIII", "Apollo XX", "Undefined"};
	TabSheet tabsheet = new TabSheet();
	
	
    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();
        
        
        layout.addComponents(new MyRichTextComponent(), tabsheet);
        
        
        createTabs();
        
        setContent(layout);
    }




	private void createTabs() {
		for (String caption: tabs) {
			VerticalLayout tabContainer = new VerticalLayout();
			tabsheet.addTab(tabContainer, caption, VaadinIcons.ANCHOR);
			
			
			createAccordionsWithinTab(tabContainer);
            
           
        }
	}

	private void createAccordionsWithinTab(VerticalLayout tabContainer) {
		Accordion ac = new Accordion();
		for (String caption: accordions) {
			VerticalLayout accordionContainer = new VerticalLayout();
			ac.addTab(accordionContainer, caption);
			tabContainer.addComponent(ac);
			
			buildRichTextArea(accordionContainer);
		}
	}

	private void buildRichTextArea(VerticalLayout accordionContainer) {
		VerticalLayout richTextContainer = new VerticalLayout();
		accordionContainer.addComponent(richTextContainer);
		richTextContainer.addComponent(new MyRichTextComponent());
	}
    
    
    

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
}

A component

package com.example.binder.test;

import com.vaadin.data.Binder;
import com.vaadin.ui.Label;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.VerticalLayout;

public class MyRichTextComponent extends VerticalLayout {

	private static final long serialVersionUID = -5037141605397053284L;

	Binder<Dummy> binder = new Binder<Dummy>(Dummy.class);
	
	RichTextArea rich = new RichTextArea();
	Dummy dummy = new Dummy();
	
	public MyRichTextComponent() {
		super();
		this.setSizeFull();
		
		dummy.setText("The quick brown fox jumps!!!");
		binder.bind(rich, Dummy::getText, Dummy::setText);
		binder.readBean(dummy);
		
		addComponents(new Label("Editor"), rich);
		
	}
	
	static class Dummy {
		private String text;

		public String getText() {
			return text;
		}

		public void setText(String text) {
			this.text = text;
		}
	}
}

If you create a project and copy and paste the clases, you should reproduce the problem…
17315600.png
17315603.png

Can you simplify that down a bit? There’s quite a lot of code there that’s not related to binding at all.

I’ve making some tests and seems the problem is in the Accordion component.

When a RichtextArea component with a binder (even without the binder doesn’t work) is added into the accordion, data is not displayed although data is in the component because it can be displayed with a notification, for example.

Here is the testing project: https://github.com/igux28/binder-vaadin8

17315979.png
17315982.png
17315985.png
17315988.png

Sorry Olli, I didn’t read your post before posting my last one.

I think the problem has nothing to do with the binder.

I’ve added vaadin 7 compatibility package to the project, and added both Vaadin 8 and Vaadin 7 RichTextArea within an accordion, and the one from Vaadin 8 shows no defaults value and the Vaadin 7 does.

So I think it’s better to close this post and start a new one in Framework UI, which I think is the right place.

I`ve pushed into github the last changes I talked about so you can try if you want.

https://github.com/igux28/binder-vaadin8

Thanks !!!

I think that my problem is this: https://vaadin.com/forum/thread/16862536

Yep, looks like the same issue.