Search in sources :

Example 1 with WDialog

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

the class WDialogRenderer method doRender.

/**
 * Paints the given WDialog.
 *
 * @param component the WDialog to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WDialog dialog = (WDialog) component;
    int state = dialog.getState();
    if (state == WDialog.ACTIVE_STATE || dialog.getTrigger() != null) {
        int width = dialog.getWidth();
        int height = dialog.getHeight();
        String title = dialog.getTitle();
        XmlStringBuilder xml = renderContext.getWriter();
        xml.appendTagOpen("ui:dialog");
        xml.appendAttribute("id", component.getId());
        xml.appendOptionalAttribute("class", component.getHtmlClass());
        xml.appendOptionalAttribute("track", component.isTracking(), "true");
        xml.appendOptionalAttribute("width", width > 0, width);
        xml.appendOptionalAttribute("height", height > 0, height);
        xml.appendOptionalAttribute("modal", dialog.getMode() == WDialog.MODAL, "true");
        xml.appendOptionalAttribute("open", dialog.getState() == WDialog.ACTIVE_STATE, "true");
        xml.appendOptionalAttribute("title", title);
        DialogOpenTrigger trigger = dialog.getTrigger();
        if (trigger != null) {
            xml.appendOptionalAttribute("triggerid", trigger.getId());
            if (dialog.hasLegacyTriggerButton()) {
                xml.appendClose();
                trigger.paint(renderContext);
                xml.appendEndTag("ui:dialog");
            } else {
                xml.appendEnd();
            }
        } else {
            xml.appendEnd();
        }
    }
}
Also used : WDialog(com.github.bordertech.wcomponents.WDialog) DialogOpenTrigger(com.github.bordertech.wcomponents.DialogOpenTrigger) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 2 with WDialog

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

the class WDialogRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WDialog dialog = new WDialog();
    dialog.setTitle(TEST_TITLE);
    dialog.setMode(WDialog.MODAL);
    setActiveContext(createUIContext());
    dialog.setTitle(getMaliciousAttribute());
    dialog.display();
    assertSafeContent(dialog);
}
Also used : WDialog(com.github.bordertech.wcomponents.WDialog) Test(org.junit.Test)

Example 3 with WDialog

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

the class WDialogRenderer_Test method testDoRender.

@Test
public void testDoRender() throws IOException, SAXException, XpathException {
    WDialog dialog = new WDialog();
    dialog.setTitle(TEST_TITLE);
    dialog.setMode(WDialog.MODELESS);
    dialog.setWidth(0);
    dialog.setHeight(0);
    dialog.setLocked(true);
    String xml = renderDialog(dialog);
    assertXpathEvaluatesTo(dialog.getId(), "//ui:dialog/@id", xml);
    assertXpathNotExists("//ui:dialog/@modal", xml);
    assertXpathEvaluatesTo(TEST_TITLE, "//ui:dialog/@title", xml);
    assertXpathNotExists("//ui:dialog/@width", xml);
    assertXpathNotExists("//ui:dialog/@height", xml);
    assertXpathNotExists("//ui:dialog/@triggerid", xml);
    int width = 123;
    int height = 456;
    dialog.setWidth(width);
    dialog.setHeight(height);
    xml = renderDialog(dialog);
    assertXpathEvaluatesTo(String.valueOf(width), "//ui:dialog/@width", xml);
    assertXpathEvaluatesTo(String.valueOf(height), "//ui:dialog/@height", xml);
    dialog.setMode(WDialog.MODAL);
    xml = renderDialog(dialog);
    assertXpathEvaluatesTo("true", "//ui:dialog/@modal", xml);
}
Also used : WDialog(com.github.bordertech.wcomponents.WDialog) Test(org.junit.Test)

Example 4 with WDialog

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

the class WDialogRenderer_Test method testRenderTrigger.

@Test
public void testRenderTrigger() throws IOException, SAXException, XpathException {
    WButton trigger = new WButton("Launch dialog");
    WButton content = new WButton("Dialog content");
    WDialog dialog = new WDialog(content, trigger);
    assertXpathExists("//ui:dialog", dialog);
    assertXpathEvaluatesTo(dialog.getId(), "//ui:dialog/@id", dialog);
    assertXpathNotExists("//ui:dialog/@open", dialog);
    assertXpathEvaluatesTo(trigger.getId(), "//ui:dialog/html:button/@id", dialog);
    assertXpathEvaluatesTo(trigger.getId(), "//ui:dialog/@triggerid", dialog);
}
Also used : WDialog(com.github.bordertech.wcomponents.WDialog) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 5 with WDialog

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

the class WDialogRenderer_Test method testSchemaMatch.

@Test
public void testSchemaMatch() throws IOException, SAXException {
    WDialog dialog = new WDialog();
    dialog.setTitle(TEST_TITLE);
    dialog.setMode(WDialog.MODAL);
    setActiveContext(createUIContext());
    dialog.display();
}
Also used : WDialog(com.github.bordertech.wcomponents.WDialog) Test(org.junit.Test)

Aggregations

WDialog (com.github.bordertech.wcomponents.WDialog)6 Test (org.junit.Test)5 DialogOpenTrigger (com.github.bordertech.wcomponents.DialogOpenTrigger)1 WButton (com.github.bordertech.wcomponents.WButton)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1