Friday, May 18, 2018

Set Initial Focus in first field of Af:table

af:table properties --> Display row = selected and Content Delivery = immediate


    /**
        * To set focus in first field of af:table
        *
        */
       public static void setFocusInTableFirstField(RichTable table,String componentId){
           FacesContext facesContext = FacesContext.getCurrentInstance();
           String tableId = table.getClientId(facesContext);
           RowKeySet rks = table.getSelectedRowKeys();
           String inputId = null;
           if (rks != null && rks.size() > 0) {
               Object rowKey = rks.iterator().next();
               String rowId = table.getClientRowKeyManager().getClientRowKey(facesContext, table, rowKey);
               inputId = tableId + ":" + rowId + ":" + componentId;
               System.out.println("@@ClientId Value:" + inputId);
           } else {
               // handle error
           }
         
           ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
           service.addScript(facesContext,  "   var comp = AdfPage.PAGE.findComponent('"+inputId+"');" +
                                            "   if(comp!=undefined){ comp.focus(); } ");
       }



Add Row Action -->
---------------------
    public oracle.binding.BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

    public String detailAddRow_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = bindings.getOperationBinding("CreateInsert1");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        ReusableCode.setFocusInTableFirstField(getT1(), "prodCodeId");
        return null;
    }

No comments:

Post a Comment