/** * {@inheritDoc} */ @Override public void setFocusRequired(final boolean b) { backing.setFocusRequired(b); }
/** * Override serviceRequest in order to perform processing specific to this interceptor. * * @param request the request being responded to. */ @Override public void serviceRequest(final Request request) { // Reset the focus for this new request. UIContext uic = UIContextHolder.getCurrent(); uic.setFocussed(null, null); // We've hit the action phase, so we do want focus on this app. uic.setFocusRequired(true); super.serviceRequest(request); }
@Test public void testFocusRequiredAccessors() { UIContext uic = createUIContext(); Assert.assertFalse("Focus required should be false by default", uic.isFocusRequired()); uic.setFocusRequired(true); Assert.assertTrue("Focus required should be true", uic.isFocusRequired()); }
/** * Override paint in order to perform processing specific to this interceptor. * * @param renderContext the renderContext to send the output to. */ @Override public void paint(final RenderContext renderContext) { getBackingComponent().paint(renderContext); // We don't want to remember the focus for the next render because on // a multi portlet page, we'd end up with multiple portlets trying to // set the focus. UIContext uic = UIContextHolder.getCurrent(); if (uic.isFocusRequired()) { boolean sticky = ConfigurationProperties.getStickyFocus(); if (!sticky) { uic.setFocussed(null, null); uic.setFocusRequired(false); } } } }
@Test public void testRenderedFormatWithFocussedComponent() throws XpathException, IOException, SAXException { MockWEnvironment environment = new MockWEnvironment(); WApplication application = new WApplication(); environment.setPostPath("WApplicationRendererTest.postPath"); WTextField focussedComponent = new WTextField(); application.add(focussedComponent); UIContext uic = createUIContext(); uic.setEnvironment(environment); uic.setUI(application); uic.setFocusRequired(true); uic.setFocussed(focussedComponent); setActiveContext(uic); assertSchemaMatch(application); assertXpathEvaluatesTo(environment.getPostPath(), "//ui:application/@applicationUrl", application); assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application); assertXpathEvaluatesTo(environment.getWServletPath(), "//ui:application/@ajaxUrl", application); assertXpathEvaluatesTo(focussedComponent.getId(), "//ui:application/@defaultFocusId", application); uic.setFocusRequired(false); assertXpathNotExists("//ui:application/@defaultFocusId", application); }