still to fill in details but heres the idea
-- bind query to backing bean
-- get Id from bound query and inject some javascript with the id.
public void focus(UIXComponent comp) {
StringBuilder script = new StringBuilder();
FacesContext context = FacesContext.getCurrentInstance();
script.add("var elem = document.getElementById(").append(comp.getClientId(context)).append("); if (elem != null) {elem.focus();}");
Service.getRenderKitService(context, ExtendedRenderKitService.class).addScript(context, script.toString());
}
-- viola
ok after some pain here is the javascript function that works on ie and firefox
function focusField(elementId) {
var comp = document.getElementById(elementId);
if (comp != null) {
comp.focus();
comp.select();
}
}
NOTE: On some screens the auto focus does not work because the component does not have an id or children(has not been initialized etc) for this just run the method bound to the value attribute on component after the one you want to focus or create a dummy. ie
in the java : {public String getAutoFocus() { focus(focusField); return "";}}
Remeber this method will be called more than once so it may have undesired results.
-- bind query to backing bean
-- get Id from bound query and inject some javascript with the id.
public void focus(UIXComponent comp) {
StringBuilder script = new StringBuilder();
FacesContext context = FacesContext.getCurrentInstance();
script.add("var elem = document.getElementById(").append(comp.getClientId(context)).append("); if (elem != null) {elem.focus();}");
Service.getRenderKitService(context, ExtendedRenderKitService.class).addScript(context, script.toString());
}
-- viola
ok after some pain here is the javascript function that works on ie and firefox
function focusField(elementId) {
var comp = document.getElementById(elementId);
if (comp != null) {
comp.focus();
comp.select();
}
}
NOTE: On some screens the auto focus does not work because the component does not have an id or children(has not been initialized etc) for this just run the method bound to the value attribute on component after the one you want to focus or create a dummy. ie
in the java : {public String getAutoFocus() { focus(focusField); return "";}}
Remeber this method will be called more than once so it may have undesired results.
Comments
Post a Comment