Search in sources :

Example 1 with WebComponent

use of org.apache.wicket.markup.html.WebComponent in project wicket by apache.

the class WicketMessageTagHandler method resolve.

@Override
public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag) {
    // localize any raw markup that has wicket:message attrs
    if ((tag != null) && (tag.getId().startsWith(getWicketMessageIdPrefix(markupStream)))) {
        Component wc;
        String id = tag.getId();
        if (tag.isOpenClose()) {
            wc = new WebComponent(id);
        } else {
            wc = new TransparentWebMarkupContainer(id);
        }
        return wc;
    }
    return null;
}
Also used : WebComponent(org.apache.wicket.markup.html.WebComponent) TransparentWebMarkupContainer(org.apache.wicket.markup.html.TransparentWebMarkupContainer) WebComponent(org.apache.wicket.markup.html.WebComponent) Component(org.apache.wicket.Component)

Example 2 with WebComponent

use of org.apache.wicket.markup.html.WebComponent in project wicket by apache.

the class MarkupContainerTest method iteratorOrder.

/**
 * Make sure components are iterated in the order they were added. Required e.g. for Repeaters
 */
@Test
public void iteratorOrder() {
    MarkupContainer container = new WebMarkupContainer("component");
    for (int i = 0; i < 10; i++) {
        container.add(new WebComponent(Integer.toString(i)));
    }
    int i = 0;
    for (Component component : container) {
        assertEquals(Integer.toString(i++), component.getId());
    }
}
Also used : WebComponent(org.apache.wicket.markup.html.WebComponent) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) WebComponent(org.apache.wicket.markup.html.WebComponent) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Example 3 with WebComponent

use of org.apache.wicket.markup.html.WebComponent in project wicket by apache.

the class JavaSerializerTest method notSerializable.

/**
 * https://issues.apache.org/jira/browse/WICKET-4812
 *
 * Tests that serialization fails when using the default ObjectOutputStream in
 * JavaSerializer and some object in the tree is not Serializable
 */
@Test
public void notSerializable() {
    JavaSerializer serializer = new JavaSerializer("JavaSerializerTest");
    WebComponent component = new NotSerializableComponent("id");
    byte[] serialized = serializer.serialize(component);
    assertNull("The produced byte[] must be null if there was an error", serialized);
}
Also used : WebComponent(org.apache.wicket.markup.html.WebComponent) Test(org.junit.Test)

Example 4 with WebComponent

use of org.apache.wicket.markup.html.WebComponent in project wicket by apache.

the class JavaSerializerTest method notDetachedModel.

/**
 * https://issues.apache.org/jira/browse/WICKET-4812
 *
 * Tests that the serialization fails when a checking ObjectOutputStream is
 * used with NotDetachedModelChecker and there is a non-detached LoadableDetachableModel
 * in the object tree.
 */
@Test
public void notDetachedModel() {
    JavaSerializer serializer = new JavaSerializer("JavaSerializerTest") {

        @Override
        protected ObjectOutputStream newObjectOutputStream(OutputStream out) throws IOException {
            IObjectChecker checker = new NotDetachedModelChecker();
            return new CheckingObjectOutputStream(out, checker);
        }
    };
    IModel<String> model = new NotDetachedModel();
    model.getObject();
    WebComponent component = new WebComponent("id", model);
    byte[] serialized = serializer.serialize(component);
    assertNull("The produced byte[] must be null if there was an error", serialized);
}
Also used : WebComponent(org.apache.wicket.markup.html.WebComponent) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CheckingObjectOutputStream(org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) CheckingObjectOutputStream(org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream) IObjectChecker(org.apache.wicket.core.util.objects.checker.IObjectChecker) NotDetachedModelChecker(org.apache.wicket.core.util.objects.checker.NotDetachedModelChecker) Test(org.junit.Test)

Example 5 with WebComponent

use of org.apache.wicket.markup.html.WebComponent in project midpoint by Evolveum.

the class CompositedIconPanel method initLayout.

private void initLayout() {
    WebMarkupContainer layeredIcon = new WebMarkupContainer(ID_LAYERED_ICON);
    layeredIcon.add(AttributeAppender.append("title", (IModel<String>) () -> {
        if (getModelObject() != null && org.apache.commons.lang3.StringUtils.isNotBlank(getModelObject().getTitle())) {
            return getModelObject().getTitle();
        }
        return null;
    }));
    add(layeredIcon);
    WebComponent basicIcon = new WebComponent(ID_BASIC_ICON);
    basicIcon.add(AttributeAppender.append("class", (IModel<String>) () -> {
        if (getModelObject() != null && getModelObject().hasBasicIcon()) {
            return getModelObject().getBasicIcon();
        }
        return null;
    }));
    basicIcon.add(AttributeAppender.append("style", (IModel<String>) () -> {
        if (getModelObject() != null && getModelObject().hasBasicIcon() && getModelObject().hasBasicIconHtmlColor()) {
            return "color:" + getModelObject().getBasicIconHtmlColor();
        }
        return null;
    }));
    layeredIcon.add(basicIcon);
    ListView<LayerIcon> validationItems = new ListView<LayerIcon>(ID_LAYER_ICONS, new PropertyModel(getModel(), CompositedIcon.F_LAYER_ICONS)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<LayerIcon> item) {
            if (item.getModelObject() == null) {
                return;
            }
            if (StringUtils.isNotEmpty(item.getModelObject().getIconType().getCssClass())) {
                WebComponent icon = new WebComponent(ID_LAYER_ICON);
                icon.add(AttributeAppender.append("class", item.getModelObject().getIconType().getCssClass()));
                if (StringUtils.isNotEmpty(item.getModelObject().getIconType().getColor())) {
                    icon.add(AttributeAppender.append("style", "color: " + item.getModelObject().getIconType().getColor()));
                }
                item.add(icon);
            }
        }
    };
    layeredIcon.add(validationItems);
    add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModelObject() != null;
        }
    });
}
Also used : WebComponent(org.apache.wicket.markup.html.WebComponent) IModel(org.apache.wicket.model.IModel) ListView(org.apache.wicket.markup.html.list.ListView) PropertyModel(org.apache.wicket.model.PropertyModel) ListItem(org.apache.wicket.markup.html.list.ListItem) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) LayerIcon(com.evolveum.midpoint.gui.impl.component.icon.LayerIcon) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Aggregations

WebComponent (org.apache.wicket.markup.html.WebComponent)11 Test (org.junit.Test)8 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)3 ObjectOutputStream (java.io.ObjectOutputStream)2 OutputStream (java.io.OutputStream)2 Component (org.apache.wicket.Component)2 MockPageWithLinkAndComponent (org.apache.wicket.MockPageWithLinkAndComponent)2 LayerIcon (com.evolveum.midpoint.gui.impl.component.icon.LayerIcon)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 MockPageWithLink (org.apache.wicket.MockPageWithLink)1 TestPage_1 (org.apache.wicket.TestPage_1)1 AjaxEventBehavior (org.apache.wicket.ajax.AjaxEventBehavior)1 Behavior (org.apache.wicket.behavior.Behavior)1 CheckingObjectOutputStream (org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream)1