@Test public void test() { FocusManager focusManager = new FocusManagerImpl(); focusManager.focus(null); verify(attributes).put(FocusManager.FOCUS_CONTEXT_ATTRIBUTE, null); assertFalse(FocusRendererUtils.isFocusEnforced(facesContext)); verifyZeroInteractions(javaScriptService); }
@Override public void focus(String componentId) { FacesContext context = FacesContext.getCurrentInstance(); if (context == null) { throw new IllegalStateException(FocusManager.class.getSimpleName() + " can't be used without FacesContext available"); } if (componentId == null) { setContextAttribute(context, null); } else { UIComponent currentComponent = UIComponent.getCurrentComponent(context); if (currentComponent == null) { currentComponent = context.getViewRoot(); } currentComponent.findComponent(componentId); UIComponent component = RendererUtils.getInstance().findComponentFor(currentComponent, componentId); if (component == null) { String message = FocusManager.class.getSimpleName() + ": Component with ID '" + componentId + "' was not found"; LOG.warn(message); context.addMessage(null, new FacesMessage(message)); } else { String clientId = component.getClientId(context); setContextAttribute(context, clientId); JavaScriptService javaScriptService = ServiceTracker.getService(context, JavaScriptService.class); javaScriptService.addPageReadyScript(context, new JSLiteral(String.format(SCRIPT, clientId))); } } }
FocusManagerImpl implements FocusManager { @Override public void focus(String componentId) { FacesContext context = FacesContext.getCurrentInstance(); if (context == null) { throw new IllegalStateException(FocusManager.class.getSimpleName() + " can't be used without FacesContext available"); } if (componentId == null) { setContextAttribute(context, null); } else { UIComponent currentComponent = UIComponent.getCurrentComponent(context); if (currentComponent == null) { currentComponent = context.getViewRoot(); } currentComponent.findComponent(componentId); UIComponent component = RendererUtils.getInstance().findComponentFor(currentComponent, componentId); if (component == null) { String message = FocusManager.class.getSimpleName() + ": Component with ID '" + componentId + "' was not found"; LOG.warn(message); context.addMessage(null, new FacesMessage(message)); } else { String clientId = component.getClientId(context); setContextAttribute(context, clientId); JavaScriptService javaScriptService = ServiceTracker.getService(context, JavaScriptService.class); javaScriptService.addPageReadyScript(context, new JSLiteral(String.format(SCRIPT, clientId))); } } } }
FocusManagerImpl implements FocusManager { @Override public void focus(String componentId) { FacesContext context = FacesContext.getCurrentInstance(); if (context == null) { throw new IllegalStateException(FocusManager.class.getSimpleName() + " can't be used without FacesContext available"); } if (componentId == null) { setContextAttribute(context, null); } else { UIComponent currentComponent = UIComponent.getCurrentComponent(context); if (currentComponent == null) { currentComponent = context.getViewRoot(); } currentComponent.findComponent(componentId); UIComponent component = RendererUtils.getInstance().findComponentFor(currentComponent, componentId); if (component == null) { String message = FocusManager.class.getSimpleName() + ": Component with ID '" + componentId + "' was not found"; LOG.warn(message); context.addMessage(null, new FacesMessage(message)); } else { String clientId = component.getClientId(context); setContextAttribute(context, clientId); JavaScriptService javaScriptService = ServiceTracker.getService(context, JavaScriptService.class); javaScriptService.addPageReadyScript(context, new JSLiteral(String.format(SCRIPT, clientId))); } } }  }
FocusManagerImpl implements FocusManager { @Override public void focus(String componentId) { FacesContext context = FacesContext.getCurrentInstance(); if (context == null) { throw new IllegalStateException(FocusManager.class.getSimpleName() + " can't be used without FacesContext available"); } if (componentId == null) { setContextAttribute(context, null); } else { UIComponent currentComponent = UIComponent.getCurrentComponent(context); if (currentComponent == null) { currentComponent = context.getViewRoot(); } currentComponent.findComponent(componentId); UIComponent component = RendererUtils.getInstance().findComponentFor(currentComponent, componentId); if (component == null) { String message = FocusManager.class.getSimpleName() + ": Component with ID '" + componentId + "' was not found"; LOG.warn(message); context.addMessage(null, new FacesMessage(message)); } else { String clientId = component.getClientId(context); setContextAttribute(context, clientId); JavaScriptService javaScriptService = ServiceTracker.getService(context, JavaScriptService.class); javaScriptService.addPageReadyScript(context, new JSLiteral(String.format(SCRIPT, clientId))); } } }  @Override void focus(String componentId); }
FocusManagerImpl implements FocusManager { @Override public void focus(String componentId) { FacesContext context = FacesContext.getCurrentInstance(); if (context == null) { throw new IllegalStateException(FocusManager.class.getSimpleName() + " can't be used without FacesContext available"); } if (componentId == null) { setContextAttribute(context, null); } else { UIComponent currentComponent = UIComponent.getCurrentComponent(context); if (currentComponent == null) { currentComponent = context.getViewRoot(); } currentComponent.findComponent(componentId); UIComponent component = RendererUtils.getInstance().findComponentFor(currentComponent, componentId); if (component == null) { String message = FocusManager.class.getSimpleName() + ": Component with ID '" + componentId + "' was not found"; LOG.warn(message); context.addMessage(null, new FacesMessage(message)); } else { String clientId = component.getClientId(context); setContextAttribute(context, clientId); JavaScriptService javaScriptService = ServiceTracker.getService(context, JavaScriptService.class); javaScriptService.addPageReadyScript(context, new JSLiteral(String.format(SCRIPT, clientId))); } } }  @Override void focus(String componentId);  }