Tuesday, April 9, 2013
ADF set Focus on Table Component
Write Below piece of code in Action / ActionListener
//t1 -- Your Table Id
//it1-- Your text component inside table
.........
FacesContext ctx = FacesContext.getCurrentInstance();
String tableId = t1.getClientId(FacesContext.getCurrentInstance());
String inputId = "";
RowKeySet rks = t1.getSelectedRowKeys();
if(rks != null && rks.size() > 0) {
Object rowKey = rks.iterator().next();
String rowId = t1.getClientRowKeyManager().getClientRowKey(FacesContext.getCurrentInstance(), t1, rowKey);
inputId = tableId + ":" + rowId + ":" + "it1";
}
//compose JavaScript to be executed on the client
StringBuilder script = new StringBuilder();
//use client id to ensure component is found if located in
//naming container
script.append("var textInput = ");
script.append("AdfPage.PAGE.findComponentByAbsoluteId");
script.append ("('"+inputId+"');");
script.append("if(textInput != null){");
script.append("textInput.focus();");
script.append("}");
//invoke JavaScript
writeJavaScriptToClient(script.toString());
.........
public static void writeJavaScriptToClient(String script) {
FacesContext fctx = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks = null;
erks = Service.getRenderKitService(
fctx, ExtendedRenderKitService.class);
erks.addScript(fctx, script);
}
Detail Explanation can be found at
http://www.bartkummel.net/2009/11/oracle-adf-set-focus-to-input-field-in-data-table/
References
https://blogs.oracle.com/jdevotnharvest/entry/how_to_programmatically_set_focus
https://blogs.oracle.com/shay/entry/controlling_tab_order_in_an_ad
http://technology.amis.nl/2008/01/04/adf-11g-rich-faces-focus-on-field-after-button-press-or-ppr-including-javascript-in-ppr-response-and-clientlisteners-client-side-programming-in-adf-faces-rich-client-components-part-2/
Subscribe to:
Posts (Atom)