jsficefacesjsf-1.2icefaces-1.8

Icefaces set focus not working


I am trying to set focus to a component in Icefaces 1.8.2, but it doesn't work probably because of the component not being rendered at the time of the method call. Any ideas?

JavascriptContext.addJavascriptCall(getContext(),
                "document.getElementById('"+ getClientId(component) + "').focus();");

Solution

  • This works, I messed it up somewhere previously..

    JavascriptContext.applicationFocus(getContext(), getClientId(component));
    
    
    public static String getClientId(UIComponent component) {
        return component.getClientId(getContext());
    }
    
    public static FacesContext getContext() {
        return FacesContext.getCurrentInstance();
    }