How to get the multi selected entity in a table component and insert/add to another entity/database table?

How to get multi selected entity values in a table component one by one and insert these values into another database table? I want to iterate all selected rows and get the value of it. After this, I would add these values into multi entities then insert into table. Could you share the full example code? I’m new to Java and Cuba. I have many questions. Thank you very much.

Below is my table.

        <table id="ccsWoesTable"
                <action id="create"/>
                <action id="edit"/>
                <action id="remove"/>
                <column id="wodate"/>
                <column id="dpment"/>
                <column id="shf"/>
                <column id="begintime"/>
                <column id="endtime"/>
                <column id="hrs"/>
                <column id="item"/>
                <column id="mach"/>
                <column id="stdp"/>
            <rows datasource="ccsWoesDs"/>
            <buttonsPanel id="buttonsPanel"
                <button id="createBtn"
                <button id="editBtn"
                <button id="removeBtn"

For example, I selected two rows. I want to click btn_upload to insert into another entity/table from the values I select.


Briefly, you need to 1) get selected rows (Table’s getSelected() method), 2) create a set of entities that duplicates the selected rows (metadata.create()), 3) save the set of new entites in DB (dataManager.commit()).

Now let’s see these steps in details.

For example, you want to save the selected Customer entity instances to another database table. To do this, you should create a new entity that duplicates Customer but is bound to another table in DB. By default, the entity inheritance strategy is SINGLE_TABLE, so you should change it to TABLE_PER_CLASS:

@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "SALES_CUSTOMER")
@Entity(name = "sales$Customer")
public class Customer extends StandardEntity {
    private static final long serialVersionUID = -6018518150505269719L;

    @Column(name = "NAME", nullable = false, length = 100)
    protected String name;

    @Column(name = "EMAIL", length = 100)
    protected String email;

    public void setName(String name) { = name;

    public String getName() {
        return name;

    public void setEmail(String email) { = email;

    public String getEmail() {
        return email;


The new CopiedCustomer entity extends Customer to avoid duplicating the code:

@Entity(name = "sales$CopiedCustomer")
public class CopiedCustomer extends Customer {
    private static final long serialVersionUID = 6675598050120952818L;

In the customer-browse XML descriptor let’s create a button that invokes the copySelectedItemsToDb() method:

<button id="copySelectedBtn"
    caption="Copy selected to DB"

In the CustomerBrowse Java controller we create this method and implement the logic I described above:

public class CustomerBrowse extends AbstractLookup {
    private GroupTable<Customer> customersTable;
    private Metadata metadata;
    private DataManager dataManager;

    public void copySelectedItemsToDb() {
        if (customersTable.getSelected() != null) {
            Set<CopiedCustomer> customersToCopy = new HashSet<>();
            for (Customer customer : customersTable.getSelected()) {
                CopiedCustomer copiedCustomer = metadata.create(CopiedCustomer.class);
            CommitContext context = new CommitContext(customersToCopy);
            showNotification(customersToCopy.size() + " customers have been copied to DB");

I hope that helped.

Thank you. I have a requirement that loop the table multi rows. I did it by getItems() and a “for” loop. Is it OK?

Collection<CcsWo> woList = ccsWoesDs.getItems();
        for (CcsWo wo : woList) {
            String JdeYN = wo.getJdeyn().toString();
            if (JdeYN.equals("N") == true) {
                CcLbmast woorder = wo.getWo();
                String woNum = woorder.getAajono();
                String curwoDate = sdfWodate.format(wo.getWodate());
                if (curwoDate.equals(woDateStr) && 
 wo.getShf().equals(convertShift(shiftField.getValue()))) {
                    CcsSummary CcsSummarydata = convertToSUMMARYModel(wo);
                showNotification(woNum + "upload!", NotificationType.TRAY);

It is OK if the ccsWoesDs is populated with the items you need.
To track the rows selected in the table, you need the table.getSelected() method anyway.

P.S. if (JdeYN.equals("N")) is enough, == true is redundant here.