Search in sources :

Example 1 with AjaxTarget

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

the class RepeaterExampleWithStaticIDs method createAddContactSubForm.

/**
 * Create the UI artefacts for the "Add contact" sub form.
 */
private void createAddContactSubForm() {
    add(new WHeading(HeadingLevel.H3, "Add a new contact"));
    WButton addBtn = new WButton("Add");
    addBtn.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            addNewContact();
        }
    });
    addBtn.setImage("/image/address-book-new.png");
    newNameField.setDefaultSubmitButton(addBtn);
    WContainer container = new WContainer();
    container.add(newNameField);
    container.add(addBtn);
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    layout.addField("New contact name", container);
    add(new WAjaxControl(addBtn, new AjaxTarget[] { repeater, newNameField }));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WContainer(com.github.bordertech.wcomponents.WContainer) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) AjaxTarget(com.github.bordertech.wcomponents.AjaxTarget)

Example 2 with AjaxTarget

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

the class TreePicker method buildUI.

/**
 * Add all the bits in the right order.
 */
private void buildUI() {
    add(new WSkipLinks());
    // the application header
    add(headerPanel);
    headerPanel.add(new UtilityBar());
    headerPanel.add(new WHeading(HeadingLevel.H1, "WComponents"));
    // mainPanel holds the menu and the actual example.
    add(mainPanel);
    mainPanel.add(menuPanel);
    mainPanel.add(exampleSection);
    // An application footer?
    WPanel footer = new WPanel(WPanel.Type.FOOTER);
    footer.add(lastLoaded);
    add(footer);
    add(new WAjaxControl(menuPanel.getTree(), new AjaxTarget[] { menuPanel.getMenu(), exampleSection }));
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WSkipLinks(com.github.bordertech.wcomponents.WSkipLinks) WPanel(com.github.bordertech.wcomponents.WPanel) WHeading(com.github.bordertech.wcomponents.WHeading) AjaxTarget(com.github.bordertech.wcomponents.AjaxTarget)

Example 3 with AjaxTarget

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

the class RepeaterExampleWithEditableRows method createExampleUi.

/**
 * Add all the required UI artefacts for this example.
 */
private void createExampleUi() {
    add(new WHeading(HeadingLevel.H2, "Contacts"));
    add(repeater);
    WButton addBtn = new WButton("Add");
    addBtn.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            addNewContact();
        }
    });
    newNameField.setDefaultSubmitButton(addBtn);
    WButton printBtn = new WButton("Print");
    printBtn.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            printEditedDetails();
        }
    });
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    layout.addField("New contact name", newNameField);
    layout.addField((WLabel) null, addBtn);
    layout.addField("Print output", console);
    layout.addField((WLabel) null, printBtn);
    // Ajax controls to make things zippier
    add(new WAjaxControl(addBtn, new AjaxTarget[] { repeater, newNameField }));
    add(new WAjaxControl(printBtn, console));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) AjaxTarget(com.github.bordertech.wcomponents.AjaxTarget)

Example 4 with AjaxTarget

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

the class WAjaxControlRenderer method doRender.

/**
 * Paints the given AjaxControl.
 *
 * @param component the AjaxControl to paint
 * @param renderContext the RenderContext to paint to
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WAjaxControl ajaxControl = (WAjaxControl) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WComponent trigger = ajaxControl.getTrigger() == null ? ajaxControl : ajaxControl.getTrigger();
    int delay = ajaxControl.getDelay();
    if (ajaxControl.getTargets() == null || ajaxControl.getTargets().isEmpty()) {
        return;
    }
    // Start tag
    xml.appendTagOpen("ui:ajaxtrigger");
    xml.appendAttribute("triggerId", trigger.getId());
    xml.appendOptionalAttribute("loadOnce", ajaxControl.isLoadOnce(), "true");
    xml.appendOptionalAttribute("delay", delay > 0, delay);
    xml.appendClose();
    // Targets
    for (AjaxTarget target : ajaxControl.getTargets()) {
        xml.appendTagOpen("ui:ajaxtargetid");
        xml.appendAttribute("targetId", target.getId());
        xml.appendEnd();
    }
    // End tag
    xml.appendEndTag("ui:ajaxtrigger");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) AjaxTarget(com.github.bordertech.wcomponents.AjaxTarget)

Example 5 with AjaxTarget

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

the class WLinkRenderer method paintAjaxTrigger.

/**
 * Paint the AJAX trigger if the link has an action.
 *
 * @param link the link component being rendered
 * @param xml the XmlStringBuilder to paint to.
 */
private void paintAjaxTrigger(final WLink link, final XmlStringBuilder xml) {
    AjaxTarget[] actionTargets = link.getActionTargets();
    // Start tag
    xml.appendTagOpen("ui:ajaxtrigger");
    xml.appendAttribute("triggerId", link.getId());
    xml.appendClose();
    if (actionTargets != null && actionTargets.length > 0) {
        // Targets
        for (AjaxTarget target : actionTargets) {
            xml.appendTagOpen("ui:ajaxtargetid");
            xml.appendAttribute("targetId", target.getId());
            xml.appendEnd();
        }
    } else {
        // Target itself
        xml.appendTagOpen("ui:ajaxtargetid");
        xml.appendAttribute("targetId", link.getId());
        xml.appendEnd();
    }
    // End tag
    xml.appendEndTag("ui:ajaxtrigger");
}
Also used : AjaxTarget(com.github.bordertech.wcomponents.AjaxTarget)

Aggregations

AjaxTarget (com.github.bordertech.wcomponents.AjaxTarget)5 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)4 WHeading (com.github.bordertech.wcomponents.WHeading)3 Action (com.github.bordertech.wcomponents.Action)2 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)2 WButton (com.github.bordertech.wcomponents.WButton)2 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)2 WComponent (com.github.bordertech.wcomponents.WComponent)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WPanel (com.github.bordertech.wcomponents.WPanel)1 WSkipLinks (com.github.bordertech.wcomponents.WSkipLinks)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1