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>");
}
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);
}
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);
}
}
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());
}
}
}
use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.
the class Border method getRegionMarkup.
/**
* Returns the markup inside <wicket:border> 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;
}
Aggregations