vaadin / vaadin/framework

Table editing mode with BeanItemContainer and BeanContainer works incorrectly

Open
#4,943 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Stale v7
Dominant language
Java
Stars
1.8k
Forks
717
Avg merge
2d 6h
Merged PRs (30d)
3

Description

Originally by damian.czernous@gmail.com


  1. Bean(Item)Container expects JavaBeans that are mutable by definition.
  2. Table to bind JavaBean fields with rows uses hashed collections (HashMap) that prefers immutable objects.

When JavaBean overrides hashcode (& equals) method (e.g. to compare by value) Table can't properly refresh rows after finished editing. During Table.setEditable( false ) execution changed rows disappears.

Editing works fine for JavaBeans that don't override hashcode method.

public class JavaBean
{
  // fields with getters & setters

  @Override
  public int hashCode()
  {
    ...
  }
}

public class SomeUI extends UI
{
  private Table table;
  private Button edit;

  @Override
  protected void init( VaadinRequest vaadinRequest )
  {
    BeanItemContainer container = new BeanItemContaner( JavaBean.class );
    container.addBean( new JavaBean() );

    table = new Table( null, container );

    edit = new Button( "edit", new TurnOnOffEditingAction( table ) );

    // set content
  }
}

public class TurnOnOffEditingAction implements Button.ClickListener
{
    private final Table table;
    
    // constructor

    @Override
    public void buttonClick( Button.ClickEvent event )
    {
        if( table.isEditable() )
        {
            event.getButton().setCaption( "edit" );
            table.setEditable( false );
        }
        else
        {
            event.getButton().setCaption( "save" );
            table.setEditable( true );
        }
    }
}

Imported from https://dev.vaadin.com/ issue #13403

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the sample with BeanItemContainer, a JavaBean that overrides equals and hashCode, and a Table whose editing mode is toggled. Trace the Table editing and row-refresh path, then verify that edited rows remain present after setEditable(false) and that existing behavior still works for beans without hashCode overrides.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.