Search in sources :

Example 41 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class VelocityWriter method doReplace.

/**
 * Replaces the search string by rendering the corresponding component.
 *
 * @param search the search String that was matched.
 * @param backing the underlying writer to write the replacement to.
 */
@Override
protected void doReplace(final String search, final Writer backing) {
    WComponent component = componentsByKey.get(search);
    UIContextHolder.pushContext(uic);
    try {
        component.paint(new WebXmlRenderContext((PrintWriter) backing));
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) PrintWriter(java.io.PrintWriter)

Example 42 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WTabGroupRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    String groupName = "WTabGroupRenderer_Test.testDoPaint.groupName";
    WTabGroup tabGroup = new WTabGroup(groupName);
    WComponent wrapped = wrapTabGroup(tabGroup);
    assertXpathNotExists("//ui:tab", wrapped);
    tabGroup.addTab(new WText("dummy"), "dummy", TabMode.CLIENT);
    assertXpathExists("//ui:tab", wrapped);
    assertSchemaMatch(wrapped);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WText(com.github.bordertech.wcomponents.WText) WTabGroup(com.github.bordertech.wcomponents.WTabGroup) Test(org.junit.Test)

Example 43 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WComponentGroupRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    // Setup Group
    WComponent actionTarget1 = new WTextField();
    WComponent actionTarget2 = new WTextField();
    WComponent actionTarget3 = new WTextField();
    WComponentGroup<WComponent> group = new WComponentGroup<>();
    group.addToGroup(actionTarget1);
    group.addToGroup(actionTarget2);
    group.addToGroup(actionTarget3);
    WContainer root = new WContainer();
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(group);
    setActiveContext(createUIContext());
    // Validate Schema
    assertSchemaMatch(root);
    // Check group
    assertXpathEvaluatesTo("1", "count(//ui:componentGroup)", root);
    assertXpathEvaluatesTo("3", "count(//ui:componentGroup/ui:component)", root);
    assertXpathEvaluatesTo(group.getId(), "//ui:componentGroup/@id", root);
    assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:componentGroup/ui:component[position()=1]/@id", root);
    assertXpathEvaluatesTo(actionTarget2.getId(), "//ui:componentGroup/ui:component[position()=2]/@id", root);
    assertXpathEvaluatesTo(actionTarget3.getId(), "//ui:componentGroup/ui:component[position()=3]/@id", root);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WContainer(com.github.bordertech.wcomponents.WContainer) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 44 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class AjaxInterceptor method serviceRequest.

/**
 * {@inheritDoc}
 */
@Override
public void serviceRequest(final Request request) {
    String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
    AjaxOperation ajaxOperation = AjaxHelper.getCurrentOperation();
    if (ajaxOperation == null) {
        throw new IllegalStateException("No AJAX operation available for trigger " + triggerId + ".");
    }
    ComponentWithContext triggerWithContext = AjaxHelper.getCurrentTriggerAndContext();
    if (triggerWithContext == null) {
        throw new IllegalStateException("No component/context available for AJAX trigger " + triggerId + ".");
    }
    UIContext uic = UIContextHolder.getCurrent();
    // Reset the focus for this new request.
    uic.setFocussed(null, null);
    // We've hit the action phase, so we do want focus on this app.
    uic.setFocusRequired(true);
    // Process trigger only
    if (isProcessTriggerOnly(triggerWithContext, ajaxOperation)) {
        // Get user context
        UIContext tuic = triggerWithContext.getContext();
        UIContextHolder.pushContext(tuic);
        try {
            WComponent trigger = triggerWithContext.getComponent();
            trigger.serviceRequest(request);
            // Manually invoke laters as the InvokeLaters in the service request is not run due to the trigger
            // having a "parent"
            tuic.doInvokeLaters();
        } finally {
            UIContextHolder.popContext();
        }
    } else if ("GET".equals(request.getMethod())) {
        // GET only supports the above scenarios
        throw new IllegalStateException("GET is not supported for the AJAX trigger " + triggerId + ".");
    } else {
        // service the request
        super.serviceRequest(request);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) UIContext(com.github.bordertech.wcomponents.UIContext) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 45 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class PlainLauncher method getUI.

/**
 * This method has been overridden to load a WComponent from parameters.
 *
 * @param httpServletRequest the servlet request being handled.
 * @return the top-level WComponent for this servlet.
 */
@Override
public synchronized WComponent getUI(final Object httpServletRequest) {
    String configuredUIClassName = getComponentToLaunchClassName();
    if (sharedUI == null || !Util.equals(configuredUIClassName, uiClassName)) {
        uiClassName = configuredUIClassName;
        WComponent ui = createUI();
        if (ui instanceof WApplication) {
            sharedUI = (WApplication) ui;
        } else {
            LOG.warn("Top-level component should be a WApplication." + " Creating WApplication wrapper...");
            sharedUI = new WApplication();
            ui.setLocked(false);
            sharedUI.add(ui);
            sharedUI.setLocked(true);
        }
        if (ConfigurationProperties.getLdeServerShowMemoryProfile()) {
            ProfileContainer profiler = new ProfileContainer();
            sharedUI.setLocked(false);
            sharedUI.add(profiler);
            sharedUI.setLocked(true);
        }
    }
    return sharedUI;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WApplication(com.github.bordertech.wcomponents.WApplication) ProfileContainer(com.github.bordertech.wcomponents.monitor.ProfileContainer)

Aggregations

WComponent (com.github.bordertech.wcomponents.WComponent)107 Test (org.junit.Test)35 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)30 UIContext (com.github.bordertech.wcomponents.UIContext)20 SystemException (com.github.bordertech.wcomponents.util.SystemException)16 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)8 WApplication (com.github.bordertech.wcomponents.WApplication)8 WLabel (com.github.bordertech.wcomponents.WLabel)8 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)7 IOException (java.io.IOException)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)5 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Size (com.github.bordertech.wcomponents.Size)4 WRepeater (com.github.bordertech.wcomponents.WRepeater)4 WText (com.github.bordertech.wcomponents.WText)4 WTextField (com.github.bordertech.wcomponents.WTextField)4