Request Focus in RC 6.3.0

I am trying to using the request focus in RC 6.3 with the following codes:


 @Override
    public void init(Map<String, Object> params) {
            if ("debit".equals(e.getProperty())
                    && Iterables.getLast(journalDetailDs.getItemIds()) == e.getItem().getId()) {
                //if(debit and credit are not equal then insert new row
                //-----------------------------------------------------
                BigDecimal dr = totalDebitField.getValue();
                BigDecimal cr = totalCreditField.getValue();
                if(dr.compareTo(cr)!=0) {
                    JournalDetail line = metadata.create(JournalDetail.class);
                    line.setJournalHeader(journalHeaderDs.getItem());
                    journalDetailDs.addItem(line);
                    journalDetailTable.setSelected(line);
                    //journalDetailTable.requestFocus();
                    journalDetailTable.requestFocus(e.getItem(), e.getItem().getGlAccounts());
            }
        });
    }

The line below in above codes seem to be not correct, can you please provide an example here?


  journalDetailTable.requestFocus(e.getItem(), e.getItem().getGlAccounts());

It doesn’t look like either as follows:


journalDetailTable.requestFocus(e.getItem(), "glAccounts");

Hi,

The new Table.requestFocus method requires an item and String id of a column.

Example:


public void addRow() {
    // add new order line
    OrderLine orderLine = metadata.create(OrderLine.class);
    orderLine.setOrder(getItem());
    linesDs.addItem(orderLine);
    // set focus on the first cell of the added row
    linesTable.setSelected(orderLine);
    linesTable.requestFocus(orderLine, "title");
}

If you need to focus some row and cell right after screen opening you can do it from ready() lifecycle method:


@Override
public void ready() {
    super.ready();

    if (!linesDs.getItems().isEmpty()) {
        OrderLine lastLine = Iterables.getLast(linesDs.getItems());
        linesTable.setSelected(lastLine);
        linesTable.requestFocus(lastLine, "title");
    }
}

I’ve attached a simple project with an editable table, so you can try it in action.

table-focus.zip (30.6K)

Great! it works just fine. Thank you,