Focus in a listgrid

How can I set the focus in the first row of a component listGrid?

I have to put the focus automatically in the first row of listGrid. We need to be using the keyboard and select a row or move into and select one.

Focus in a listgrid

Hi gdperellon,

To focus a certain row in a list grid, you can set "focusedRow" property to certain list grid row id then fire "focus" event.

<b:button > select and focus first row
<e:handler event="click" type="text/javascript">
var oListGrid = bb.document.getElementById("listGrid");
oListGrid.setAttribute("selectedIndexes", "0");
oListGrid.setProperty("focusedRow", 0);
bb.command.fireEvent(oListGrid, "focus", false, false);
</e:handler>
</b:button>

hope this help,
Yudi

OK, it works but it doesn't

OK, it works but it doesn't invokes the selectListener in my BackingBean.
Do I have to do something more to invoke the listener method when a row is selected in this way?

Thanks and regards.

focusing listgrid

Hi David,

You are right, it does not call the server side SelectListener.
but you can call the customActionListener which will call the selectListener after that.
you can add the bb.bjsf.sync method like this

<f:verbatim>
        <e:handler event="pageRefreshed" type="application/javascript">
                var oListGrid = bb.document.getElementById("listGrid");
                oListGrid.setAttribute("selectedIndexes", "0");
                oListGrid.setProperty("focusedRow", 0);
                bb.command.fireEvent(oListGrid, "focus", false, false);
                bb.bjsf.sync(this, "custom", "param1", "0");
        </e:handler>
</f:verbatim>

and create the customAction method into your backing Bean

public void selectRow(CustomActionEvent event){
    System.out.println(event.getAtts().get("param1"));
    listGrid.setRowIndex(0);
    this.rowIndex = listGrid.getRowIndex();
}

Dont forget to add this code below in your listgrid instantiation

customActionListener="#{listGridBean.selectRow}"

Hope this helps,

Andys

Yes, it helps me a

Yes, it helps me a lot.
Thank you very much, andys.
Kind Regards
David