Search in sources :

Example 11 with IMarkupFragment

use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.

the class MarkupFragmentTest method fragments.

/**
 * @throws Exception
 */
@Test
public void fragments() throws Exception {
    Page page = new InlinePanelPage_1();
    Fragment fragment = (Fragment) page.get("myPanel1");
    // Get the associated markup file
    IMarkupFragment markup = fragment.getAssociatedMarkup();
    assertNull(markup);
    // getMarkup() returns the "calling" tags
    markup = fragment.getMarkup();
    compareMarkupWithString(markup, "<span wicket:id=\"myPanel1\">panel</span>");
    // getMarkup(null) returns the markup which is used to find a child component
    markup = fragment.getMarkup(null);
    compareMarkupWithString(markup, "<wicket:fragment wicket:id=\"frag1\">panel 1</wicket:fragment>");
}
Also used : InlinePanelPage_1(org.apache.wicket.markup.html.panel.InlinePanelPage_1) Page(org.apache.wicket.Page) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) Fragment(org.apache.wicket.markup.html.panel.Fragment) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) Test(org.junit.Test)

Example 12 with IMarkupFragment

use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.

the class WicketTester method assertMarkupVariation.

/**
 * Asserts that a component's markup has loaded with the given variation
 *
 * @param component
 *              The component which markup to check
 * @param expectedVariation
 *              The expected variation of the component's markup
 */
public void assertMarkupVariation(Component component, String expectedVariation) {
    Result result = Result.PASS;
    IMarkupFragment markup = getMarkupFragment(component);
    String actualVariation = markup.getMarkupResourceStream().getVariation();
    if (Objects.equal(expectedVariation, actualVariation) == false) {
        result = Result.fail(String.format("Wrong variation for component '%s'. Actual: '%s', expected: '%s'", component.getPageRelativePath(), actualVariation, expectedVariation));
    }
    assertResult(result);
}
Also used : IMarkupFragment(org.apache.wicket.markup.IMarkupFragment)

Example 13 with IMarkupFragment

use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.

the class Component method internalRenderComponent.

/**
 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!
 * <p>
 * Renders the component at the current position in the given markup stream. The method
 * onComponentTag() is called to allow the component to mutate the start tag. The method
 * onComponentTagBody() is then called to permit the component to render its body.
 */
protected final void internalRenderComponent() {
    final IMarkupFragment markup = getMarkup();
    if (markup == null) {
        throw new MarkupException("Markup not found. Component: " + toString());
    }
    final MarkupStream markupStream = new MarkupStream(markup);
    // Get mutable copy of next tag
    final ComponentTag openTag = markupStream.getTag();
    final ComponentTag tag = openTag.mutable();
    // Call any tag handler
    onComponentTag(tag);
    // If we're an openclose tag
    if (!tag.isOpenClose() && !tag.isOpen()) {
        // We were something other than <tag> or <tag/>
        markupStream.throwMarkupException("Method renderComponent called on bad markup element: " + tag);
    }
    if (tag.isOpenClose() && openTag.isOpen()) {
        markupStream.throwMarkupException("You can not modify a open tag to open-close: " + tag);
    }
    try {
        // Render open tag
        boolean renderBodyOnly = getRenderBodyOnly();
        if (renderBodyOnly) {
            ExceptionSettings.NotRenderableErrorStrategy notRenderableErrorStrategy = ExceptionSettings.NotRenderableErrorStrategy.LOG_WARNING;
            if (Application.exists()) {
                notRenderableErrorStrategy = getApplication().getExceptionSettings().getNotRenderableErrorStrategy();
            }
            if (getFlag(FLAG_OUTPUT_MARKUP_ID)) {
                String message = String.format("Markup id set on a component that renders its body only. " + "Markup id: %s, component id: %s.", getMarkupId(), getId());
                if (notRenderableErrorStrategy == ExceptionSettings.NotRenderableErrorStrategy.THROW_EXCEPTION) {
                    throw new IllegalStateException(message);
                }
                log.warn(message);
            }
            if (getFlag(FLAG_PLACEHOLDER)) {
                String message = String.format("Placeholder tag set on a component that renders its body only. " + "Component id: %s.", getId());
                if (notRenderableErrorStrategy == ExceptionSettings.NotRenderableErrorStrategy.THROW_EXCEPTION) {
                    throw new IllegalStateException(message);
                }
                log.warn(message);
            }
        } else {
            renderComponentTag(tag);
        }
        markupStream.next();
        // Render the body only if open-body-close. Do not render if open-close.
        if (tag.isOpen()) {
            // Render the body. The default strategy will simply call the component's
            // onComponentTagBody() implementation.
            getMarkupSourcingStrategy().onComponentTagBody(this, markupStream, tag);
            // Render close tag
            if (openTag.isOpen()) {
                renderClosingComponentTag(markupStream, tag, renderBodyOnly);
            } else if (renderBodyOnly == false) {
                if (needToRenderTag(openTag)) {
                    // Close the manually opened tag. And since the user might have changed the
                    // tag name ...
                    getResponse().write(tag.syntheticCloseTagString());
                }
            }
        }
    } catch (WicketRuntimeException wre) {
        throw wre;
    } catch (RuntimeException re) {
        throw new WicketRuntimeException("Exception in rendering component: " + this, re);
    }
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) MarkupException(org.apache.wicket.markup.MarkupException) ExceptionSettings(org.apache.wicket.settings.ExceptionSettings)

Example 14 with IMarkupFragment

use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.

the class Component method internalRender.

/**
 * Performs a render of this component as part of a Page level render process.
 */
private void internalRender() {
    // Make sure there is a markup available for the Component
    IMarkupFragment markup = getMarkup();
    if (markup == null) {
        throw new MarkupNotFoundException("Markup not found for Component: " + toString());
    }
    // MarkupStream is an Iterator for the markup
    MarkupStream markupStream = new MarkupStream(markup);
    MarkupElement elem = markup.get(0);
    if (elem instanceof ComponentTag) {
        // Guarantee that the markupStream is set and determineVisibility not yet tested
        // See WICKET-2049
        ((ComponentTag) elem).onBeforeRender(this, markupStream);
    }
    // and the isVisible property.
    if (determineVisibility()) {
        setFlag(FLAG_HAS_BEEN_RENDERED, true);
        // Rendering is beginning
        if (log.isDebugEnabled()) {
            log.debug("Begin render {}", this);
        }
        try {
            notifyBehaviorsComponentBeforeRender();
            onRender();
            notifyBehaviorsComponentRendered();
            // Component has been rendered
            rendered();
        } catch (RuntimeException ex) {
            onException(ex);
        }
        if (log.isDebugEnabled()) {
            log.debug("End render {}", this);
        }
    } else // elem is null when rendering a page
    if ((elem != null) && (elem instanceof ComponentTag)) {
        if (getFlag(FLAG_PLACEHOLDER)) {
            renderPlaceholderTag((ComponentTag) elem, getResponse());
        }
    }
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupNotFoundException(org.apache.wicket.markup.MarkupNotFoundException) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) MarkupElement(org.apache.wicket.markup.MarkupElement)

Example 15 with IMarkupFragment

use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.

the class Border method getRegionMarkup.

/**
 * Returns the markup inside &lt;wicket:border&gt; tag.
 * If such tag is not found, all the markup is returned.
 *
 * @see IQueueRegion#getRegionMarkup()
 */
@Override
public IMarkupFragment getRegionMarkup() {
    IMarkupFragment markup = super.getRegionMarkup();
    if (markup == null) {
        return markup;
    }
    IMarkupFragment borderMarkup = MarkupUtil.findStartTag(markup, BORDER);
    return borderMarkup != null ? borderMarkup : markup;
}
Also used : IMarkupFragment(org.apache.wicket.markup.IMarkupFragment)

Aggregations

IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)26 Test (org.junit.Test)8 Page (org.apache.wicket.Page)6 ComponentTag (org.apache.wicket.markup.ComponentTag)6 MarkupStream (org.apache.wicket.markup.MarkupStream)6 MarkupContainer (org.apache.wicket.MarkupContainer)5 MarkupException (org.apache.wicket.markup.MarkupException)4 Component (org.apache.wicket.Component)3 MarkupElement (org.apache.wicket.markup.MarkupElement)3 MarkupNotFoundException (org.apache.wicket.markup.MarkupNotFoundException)3 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 MarkupResourceStream (org.apache.wicket.markup.MarkupResourceStream)2 WicketTag (org.apache.wicket.markup.WicketTag)2 Border (org.apache.wicket.markup.html.border.Border)2 Panel (org.apache.wicket.markup.html.panel.Panel)2 IComponentResolver (org.apache.wicket.markup.resolver.IComponentResolver)2 IOException (java.io.IOException)1 List (java.util.List)1