Table editing mode with BeanItemContainer and BeanContainer works incorrectly
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 717
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 3
Description
Originally by damian.czernous@gmail.com
- Bean(Item)Container expects JavaBeans that are mutable by definition.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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