Skip to main content

Auto Focus in ADF : Revisit

Auto focus on the first or name field of a jsff is difficult if it is loaded dynamically.

Here is one solution:

1) In your page or template add the following non visible text fields near the end of your page(these will set the client id of your field and execute some javascript):

<af:inputText clientComponent="true" id="hit7" value="#{formBean.focusId}" visible="false"/>

<inputText clientComponent="true" id="hit8" value="#{formBean.focusScript}" visible="false"/>

2) Backing bean (MUST use view scope):
//member variables
 private boolean mustExecuteAutoFocus = false;
 private String clientFocusId = null;
 //Constructor - this will be called when the taskflow id changes in the region
 public FormBean(){
  mustExecuteAutoFocus = true;
 }
 public String getFocusId(){
  //here you can use a bound component or find a component in the view root by id etc to get your id or just hard code it
  UIComponent comp = findFirstInputTextComponent();
  if (comp == null){
   setClientFocusId(null);
   return null;
  }
  setClientFocusId(comp.getClientId(FacesContext.getCurrentInstance()));
  return getClientFocusId();
}

public String getClientFocusId(){
 return clientFocusId;
}

public void setClientFocusId(String clientFocusId){
 this.clientFocusId = clientFocusId;
}

public String getAutoFocusClientScript(){
 if (getClientFocusId() != null && mustExecuteAutoFocus){
  executeScript("autoFocus('" + getClientFocusId() + "');");
  mustExecuteAutoFocus = false;
 }
 return "";
}


3) js
function focus(focusId) {
 var f = document.getElementById(focusId + '::content'); 
 if(f == null) {
  f = document.getElementById(focusId);
 }
 if (f != null) {
  setTimeout("focusElement('" + f.id + "');", 100);
 }
}

function focusElement(elementId) {
    var c = document.getElementById(elementId);
    if (c != null) {
        c.focus();
        c.select();
    }
}

Comments

Popular posts from this blog

OJDeploy: Documentation for the tool

Real DOCS:  http://docs.oracle.com/cd/E26098_01/user.1112/e17455/deploying_apps.htm#OJDUG645 OJDeploy Documentation if you run it from the command line - I keep looking for this so I though I would post it here so I remeber. Oracle JDeveloper Deploy 11.1.2.1.0.6081 Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. Usage:   ojdeploy -profile <name> -workspace <jws> [ -project <name> ] [ <options> ]   ojdeploy -buildfile <ojbuild.xml> [ <options> ]   ojdeploy -buildfileschema Arguments:   -profile               the name of the Profile to deploy   -workspace      full path to the JDeveloper Workspace file(.jws)   -project              name of the JDeveloper Project within the .jws where the Profile can be...

ADF: LOV Description instead of code

I keep on forgetting how to do this so this is a note to self in terms I understand (ie pictures): Add the related entiy object to yours (in the example we are adding RegionEO(list of values) to CountryEO) Now add the RegionName field from the EO and a transient attribute (I named mine RegionNameLOV) Make the transient attribute updateable and base it on the expression RegionName (the description you wish to display) Add a list of values to RegionNameLOV and map BOTH key to parent fk (region id here) AND RegionName to your transient coulmn (RegionNameLOV).  Map the transient as an Input text with List of Values. Then just drag the lov item onto the page (RegionNameLOV)

java.lang.IllegalStateException: ADF_FACES-60003:Component with ID not registered for Active Data

This was hard to fix: if anyone wants the code just ask. Or if you have a better solution please post comment. Once excel export has been clicked if we navigate around using ppr to refresh the region we get this error. I was forced to create an export handler tag wich forces the export to happen in a new window. Because this page is getting some hits here is some of the code (also use this method for pdf export): Button with new listener: (xmlns:new="http://za.co.company/adf/faces/common/my" in your jsp:root) <af:commandToolbarButton text="Export" id="ctb1" immediate="true" partialSubmit="true" icon="images/excel.jpg"> <new:myExportCollectionActionListener exportedId="audTab" type="excelHTML" filename="audit.xls" title="Audit"/> </af:commandToolbarButton> TAG: import oracle.adfinternal.view.faces.export.ExportCollectionActionListener; import oracle.adfin...