Binding One Field to Many GroupFields in Case of Table Multi Select

Hi,

I don’t know how to update more than one database records by SQLContainer using FiedlGroup.
What I want to do is to edit values of a Table in a Form, in which a fileld are all binded to some FieldGroups.
(See attahed pictures.)

Here is waht I did,

private final OptionGroup validOG = new OptionGroup();
List<FieldGroup> fgList;
private final void whenMultiSelect(Set<Object> set) {
    fgList = new ArrayList<FieldGroup>();
    for(Object o : set) {
        FieldGroup fg = new FieldGroup();
        fg.bind(validOG, "valid");
        fg.setItemDataSource(ifaceView.getItem(o));
        fg.setBuffered(false);
        fgList.add(fg);
    }
}

Only the last FieldGroup of fgList was updated.

It seemed that one FieldGoup is only one field, is it right?
Could you give me some adveice to solve the issue.

Thanks.
17947.png

I think you can wrap your table in a vaadin CustomComponent. Inside the CustomComponent you can use one FieldGroup for the content of the Table. Ask more information if needed.

Hi, thank you for your reply.

Ask more information if needed.

Could you give me where examples or documents about it.

Thanks.

Correction to my earlier answer: I meant
CustomField
not CustomComponent.

Read at least these:
https://vaadin.com/book/-/page/components.customfield.html
https://vaadin.com/book/-/page/datamodel.itembinding.html

My very quick and initial schetch how the component could look like (if I have understood your use case right)…

public class CustomTableField extends CustomField<Set<Object>> {

    private Table internalTable;

    @Override
    protected Component initContent() {
        internalTable = new Table();
        // init table
        // ...
        return internalTable;
    }

    @Override
    public Class<? extends Set<Object>> getType() {
        return (Class<? extends Set<Object>>) Set.class;
    }

    @Override
    protected void setInternalValue(Set<Object> newValue) {
        super.setInternalValue(newValue);
        // TODO select given row ids of the internalTable

    }

    @Override
    public Set<Object> getValue() {
        // TODO return selected row ids of the internalTable
        return super.getValue();
    }
    
    // other logic
}

Hi, thank your for your advice.

I read some documents, and then I tried to write a sample.

Sorry this might be a basic question, but I could’t understand. In the CustomTableField class I added ValueChangeLister, but I couldn’t because of the two errors below
.

protected Component initContent() {
    internalTable = new Table();        
    internalTable.addValueChangeListener(new ValueChangeListener() { // #1 error line
        @Override
        public void valueChange(ValueChangeEvent event) {  // #2 error line
            // TODO Auto-generated method stub
        }
    });

}

#1 error
The type new Property.ValueChangeListener(){} must implement the inherited abstract method
Property.ValueChangeListener.valueChange(Property.ValueChangeEvent)

#2 error
The method valueChange(Field.ValueChangeEvent) of type new Property.ValueChangeListener(){} must override or implement a supertype method

Do I misunderstand something?

Thanks.

I suppose you are using Eclipse? It has sometimes troubles to resolve correct imports. Try with this one:

internalTable.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(
                    com.vaadin.data.Property.ValueChangeEvent event) {
                
            }
        });

Hi,

Thanks to your advice, this problem is solved.

Thanks.