Example usage for org.apache.wicket Component setMarkupId

List of usage examples for org.apache.wicket Component setMarkupId

Introduction

In this page you can find the example usage for org.apache.wicket Component setMarkupId.

Prototype

public Component setMarkupId(String markupId) 

Source Link

Document

Sets this component's markup id to a user defined value.

Usage

From source file:com.aplombee.RepeaterUtilTest.java

License:Apache License

@Test(groups = { "utilTests" })
public void removeItem() {
    final String itemMarkupId = "76";
    Item item = Mockito.mock(Item.class);
    Mockito.when(item.getMarkupId()).thenReturn(itemMarkupId);
    Component parent = new WebMarkupContainer("p");
    parent.setMarkupId("p1");
    final String actual = RepeaterUtil.get().removeItem(item, parent);
    final String expected = "QuickView.removeItem('76','p1');";
    Assert.assertEquals(actual.trim(), expected.trim());
}

From source file:com.userweave.pages.test.BasePageSurvey.java

License:Open Source License

private void addLoadingPanel() {
    Component loading = new WebMarkupContainer("loading");
    loading.setMarkupId("loading");
    add(loading);/*  w  w w.j a  va 2  s  .c  o  m*/

    final AbstractDefaultAjaxBehavior setTimeBehaviour = new AbstractDefaultAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {
            pageLoaded(System.currentTimeMillis());
        }
    };

    // add js-function setTime to call setTimeBehaviour
    loading.add(new Behavior() {
        private static final long serialVersionUID = 1L;

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            String jsCall = "function setTime() { wicketAjaxGet( '" + setTimeBehaviour.getCallbackUrl()
                    + "', null, null, null); }";

            response.renderJavaScript(jsCall, null);
        }
    });

    loading.add(setTimeBehaviour);
}

From source file:com.wiquery.plugins.jqgrid.component.XMLDataRequestTarget.java

License:Apache License

/**
 * Adds a component to the list of components to be rendered
 * //ww w  . ja v a2  s  . co m
 * @param markupId
 *            id of client-side dom element that will be updated
 * 
 * @param component
 *            component to be rendered
 */
public final void addComponent(Component component, String markupId) {
    if (Strings.isEmpty(markupId)) {
        throw new IllegalArgumentException("markupId cannot be empty");
    }
    if (component == null) {
        throw new IllegalArgumentException("component cannot be null");
    } else if (component instanceof Page) {
        if (component != page) {
            throw new IllegalArgumentException("component cannot be a page");
        }
    } else if (component instanceof AbstractRepeater) {
        throw new IllegalArgumentException("Component " + component.getClass().getName()
                + " has been added to the target. This component is a repeater and cannot be repainted via ajax directly. Instead add its parent or another markup container higher in the hierarchy.");
    }

    component.setMarkupId(markupId);
    markupIdToComponent.put(markupId, component);
}

From source file:org.artifactory.common.wicket.application.SetPathMarkupIdOnBeforeRenderListener.java

License:Open Source License

@Override
public void onBeforeRender(Component component) {
    String markupId = component.getMarkupId(false);
    if (markupId == null) {
        String id = getPath(component);
        if (id != null) {
            component.setMarkupId(id);
            component.setOutputMarkupId(true);
        }/*from   w  w w . j av a  2s  .  c  o m*/
    }
}

From source file:org.artifactory.common.wicket.util.AjaxUtils.java

License:Open Source License

public static void render(Component component, String markupId) {
    final String componentId = component.getMarkupId();
    AjaxRequestTarget.get().add(component, markupId);
    component.setMarkupId(componentId);
}

From source file:org.cdlflex.ui.markup.html.badge.BadgeListTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    List<BadgeListItem> items = new ArrayList<>();

    // only body model
    items.add(new BadgeListItem(Model.of(42)));

    // body and label model
    items.add(new BadgeListItem(Model.of(42), Model.of("Answer")));

    // body model and link
    items.add(new BadgeListItem(Model.of(42)) {
        private static final long serialVersionUID = 1L;

        @Override//from  w  ww  . j  a v  a2s  .  c  om
        public AbstractLink createLink(String id) {
            return new BookmarkablePageLink<Void>(id, DummyHomePage.class);
        }
    });
    // body and label model and link
    items.add(new BadgeListItem(Model.of(42), Model.of("Answer")) {
        private static final long serialVersionUID = 1L;

        @Override
        public AbstractLink createLink(String id) {
            return new BookmarkablePageLink<Void>(id, DummyHomePage.class);
        }
    });

    badgeList = new BadgeList("badge-list", items) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onBeforeRender() {
            // hack for allowing access in TagTester
            super.onBeforeRender();
            visitChildren(new IVisitor<Component, Void>() {
                int cnt = 0;

                @Override
                public void component(Component component, IVisit<Void> visit) {
                    component.setOutputMarkupId(true);
                    if (component instanceof ListItem) {
                        component.setMarkupId("item-" + (cnt++));
                    }
                }
            });
        }
    };

    String markup = ComponentRenderer.renderComponent(badgeList).toString();
    TagTester tag = TagTester.createTagByAttribute(markup, "wicket:id", "badge-list");

    item0 = tag.getChild("id", "item-0");
    item1 = tag.getChild("id", "item-1");
    item2 = tag.getChild("id", "item-2");
    item3 = tag.getChild("id", "item-3");
}

From source file:org.cdlflex.ui.markup.html.panel.FeedbackPanelTest.java

License:Apache License

@Test
public void multipleMessages_rendersAllMessages() throws Exception {
    FeedbackPanel panel = new FeedbackPanel("feedback", false) {
        private static final long serialVersionUID = 1L;

        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override/* w w  w .j  av  a2s.c o m*/
        protected void onBeforeRender() {
            super.onBeforeRender();
            // necessary to test the presence of all messages
            ((ListView) get("feedbackul").get("messages")).visitChildren(new IVisitor<Component, Void>() {
                int cnt = 0;

                @Override
                public void component(Component object, IVisit<Void> visit) {
                    if (object instanceof Alert) {
                        object.setOutputMarkupId(true);
                        object.setMarkupId("message-" + (cnt++));
                    }
                }
            });
        }
    };

    panel.success("success");
    panel.info("info");
    panel.debug("debug");
    panel.warn("warn");
    panel.error("error");
    panel.fatal("fatal");

    TagTester tagTester = renderAndCreateTag(panel);
    assertNotNull(tagTester.getChild("id", "message-0"));
    assertNotNull(tagTester.getChild("id", "message-1"));
    assertNotNull(tagTester.getChild("id", "message-2"));
    assertNotNull(tagTester.getChild("id", "message-3"));
    assertNotNull(tagTester.getChild("id", "message-4"));
    assertNotNull(tagTester.getChild("id", "message-5"));
    assertNull(tagTester.getChild("id", "message-6"));
}

From source file:org.efaps.ui.wicket.components.heading.HeadingPanel.java

License:Apache License

/**
 * Method to add the Component to this Panel.
 *
 * @param _headingmodel model of the heading.
 *///from   w ww.j a  va  2s.c o  m
public void addComponents(final Model<UIHeading> _headingmodel) {
    final WebMarkupContainer container = new WebMarkupContainer("container");

    this.add(container);
    if (_headingmodel.getObject().getLevel() == 0) {
        container.add(AttributeModifier.replace("class", "eFapsFrameTitle"));
    } else {
        container
                .add(AttributeModifier.replace("class", "eFapsHeading" + _headingmodel.getObject().getLevel()));
    }
    container.add(new Label("heading", _headingmodel.getObject().getLabel()));

    final String toggleId = this.getMarkupId(true);
    final Component span = new WebComponent("toggle") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onComponentTag(final ComponentTag _tag) {
            super.onComponentTag(_tag);
            _tag.put("onclick", "toggleSection('" + toggleId + "');");
        }

        @Override
        public boolean isVisible() {
            return _headingmodel.getObject().getLevel() > 0 && _headingmodel.getObject().isCollapsible();
        }
    };
    container.add(span);

    final Component status = new WebComponent("status") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onComponentTag(final ComponentTag _tag) {
            super.onComponentTag(_tag);
            _tag.put("name", _headingmodel.getObject().getName());
            _tag.put("value", false);
        }

        @Override
        public boolean isVisible() {
            return _headingmodel.getObject().getLevel() > 0 && _headingmodel.getObject().isCollapsible();
        }
    };
    status.setMarkupId("status_" + toggleId);
    container.add(status);
}

From source file:org.onexus.website.api.pages.search.figures.LinksBox.java

License:Apache License

private Component newFieldsBox(String componentId, String labelField, IEntity entity, boolean active) {

    Component box;
    if (status.getType().getTemplate() == null || status.getType().getTemplate().isEmpty()) {
        box = new FieldsPanel(componentId, labelField, entity);
    } else {//w  w  w .j a v  a 2  s  .c  o  m
        box = new Label(componentId, replaceEntityValues(status.getType().getTemplate(), entity))
                .setEscapeModelStrings(false);
    }

    if (active) {
        box.add(new AttributeAppender("class", " active"));
    }

    box.setMarkupId(entity.getId());
    return box;

}

From source file:sf.wicklet.gwt.server.ajax.impl.AbstractGwtAjaxResponse.java

License:Apache License

/**
 * Adds a component to be updated at the client side with its current markup
 *
 * @param component//w w  w.ja va2 s.c  o m
 *      the component to update
 * @param markupId
 *      the markup id to use to find the component in the page's markup
 * @throws IllegalArgumentException
 *      thrown when a Page or an AbstractRepeater is added
 * @throws IllegalStateException
 *      thrown when components no more can be added for replacement.
 */
final void add(final Component component, final String markupId)
        throws IllegalArgumentException, IllegalStateException {
    Args.notEmpty(markupId, "markupId");
    Args.notNull(component, "component");
    if (component instanceof Page) {
        if (component != page) {
            throw new IllegalArgumentException("component cannot be a page");
        }
    } else if (component instanceof AbstractRepeater) {
        throw new IllegalArgumentException("Component " + component.getClass().getName()
                + " has been added to the target. This component is a repeater and cannot be repainted via ajax directly. "
                + "Instead add its parent or another markup container higher in the hierarchy.");
    }
    assertComponentsNotFrozen();
    component.setMarkupId(markupId);
    markupIdToComponent.put(markupId, component);
}