You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Thibault Kruse <ti...@googlemail.com> on 2014/09/15 19:37:14 UTC
Programmatic Markup with fallback
Hi,
I am trying to create a wicket panel that renders markup from some
remote source, but if fetching fails, renders some fallback markup. I
want to achieve this with minimal code.
I tried two approaches one based on overriding getMarkup(), one based
on http://wicket.apache.org/guide/guide/advanced.html#advanced_5, both
fail:
/**
* attempts to use custom markup by overriding getMarkup()... but html is used
*/
public class CustomMarkupFallback1Panel extends GenericPanel<String> {
@Override
public IMarkupFragment getMarkup() {
return Markup.of("it works");
}
}
CustomMarkupFallback1Panel.html:
<wicket:panel>
Fail!
</wicket:panel>
This first one overrides getMarkup() as suggested in the javadoc of
IMarkupResourceStreamProvider, but what gets rendered is instead the
static html (even though the debugger walks through getMarkup().
The second approach fails using IMarkupResourceStreamProvider works
for the intended markup, but not for the fallback markup
public class CustomMarkupFallback2Panel extends GenericPanel<String>
IMarkupResourceStreamProvider {
@Override
public IResourceStream getMarkupResourceStream(MarkupContainer
container, Class<?> containerClass) {
if (getModelObject() == null) {
// thows Exception, see below. html file exists
return getMarkup().getMarkupResourceStream();
} else {
// works
return new StringResourceStream(getModelObject());
}
}
}
At least the first failure seems like a bug to me, not sure whether
the second approach is supposed to work, or how else to load markup
the wicket way.
Is there maybe a completely different approach to achieve what I try to do?
cheers,
Thibault
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:162)
at java.io.BufferedInputStream.read(BufferedInputStream.java:325)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at org.apache.wicket.util.io.BOMInputStream.getBOM(BOMInputStream.java:217)
at org.apache.wicket.util.io.BOMInputStream.readFirstBytes(BOMInputStream.java:261)
at org.apache.wicket.util.io.BOMInputStream.read(BOMInputStream.java:312)
at org.apache.wicket.util.io.XmlReader.getXmlDeclaration(XmlReader.java:183)
at org.apache.wicket.util.io.XmlReader.init(XmlReader.java:106)
at org.apache.wicket.util.io.XmlReader.<init>(XmlReader.java:81)
at org.apache.wicket.markup.parser.XmlPullParser.parse(XmlPullParser.java:605)
at org.apache.wicket.markup.AbstractMarkupParser.parse(AbstractMarkupParser.java:178)
at org.apache.wicket.markup.loader.SimpleMarkupLoader.loadMarkup(SimpleMarkupLoader.java:51)
at org.apache.wicket.markup.loader.InheritedMarkupMarkupLoader.loadMarkup(InheritedMarkupMarkupLoader.java:57)
at org.apache.wicket.markup.loader.DefaultMarkupLoader.loadMarkup(DefaultMarkupLoader.java:52)
at org.apache.wicket.markup.MarkupFactory.loadMarkup(MarkupFactory.java:412)
at org.apache.wicket.markup.MarkupCache.loadMarkup(MarkupCache.java:448)
at org.apache.wicket.markup.MarkupCache.loadMarkupAndWatchForChanges(MarkupCache.java:544)
at org.apache.wicket.markup.MarkupCache.getMarkup(MarkupCache.java:305)
at org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:236)
at org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:194)
at org.apache.wicket.MarkupContainer.getAssociatedMarkup(MarkupContainer.java:405)
at org.apache.wicket.MarkupContainer.getAssociatedMarkupStream(MarkupContainer.java:372)
at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHeadFromAssociatedMarkupFile(AssociatedMarkupSourcingStrategy.java:244)
at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHead(AssociatedMarkupSourcingStrategy.java:220)
at org.apache.wicket.Component.renderHead(Component.java:2652)
at org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy$1.component(ChildFirstHeaderRenderStrategy.java:85)
at org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:96)
at org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:87)
at org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:51)
at org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderChildHeaders(ChildFirstHeaderRenderStrategy.java:78)
at org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderHeader(ChildFirstHeaderRenderStrategy.java:57)
at org.apache.wicket.markup.html.internal.HtmlHeaderContainer.onComponentTagBody(HtmlHeaderContainer.java:170)
at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71)
at org.apache.wicket.Component.internalRenderComponent(Component.java:2514)
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1496)
at org.apache.wicket.Component.internalRender(Component.java:2344)
at org.apache.wicket.Component.render(Component.java:2272)
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1392)
at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1557)
at org.apache.wicket.Page.onRender(Page.java:887)
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Programmatic Markup with fallback
Posted by Andrea Del Bene <an...@gmail.com>.
Hi,
I've found a simple solution delegating markup providing to
DefaultMarkupResourceStreamProvider:
public class CustomMarkupFallback2Panel extends Panel implements
IMarkupCacheKeyProvider,
IMarkupResourceStreamProvider {
private final DefaultMarkupResourceStreamProvider
markupResourceStreamProvider =
new DefaultMarkupResourceStreamProvider();
public CustomMarkupFallback2Panel(String id, IModel<String> model) {
super(id, model);
}
@Override
public IResourceStream getMarkupResourceStream(MarkupContainer
container, Class<?> containerClass) {
if (getDefaultModelObject() == null) {
return
markupResourceStreamProvider.getMarkupResourceStream(container,
containerClass);
} else {
return new StringResourceStream("" + getDefaultModelObject());
}
}
@Override
public String getCacheKey(MarkupContainer container, Class<?>
containerClass) {
return null;
}
}
For the closed stream exception I'm opening an issue to improve code.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Programmatic Markup with fallback
Posted by Thibault Kruse <ti...@googlemail.com>.
I realize now using the wicket:panel tag only works with panels, so
maybe the wicket way to go would be to have a "raw" markup file
without the xmlns declaration. I don't know. In any case, I preferred
to use a panel with a "complete" html file like for any other panel,
so I had to circumvent the PanelMarkupSourcingStrategy from overruling
getMarkup().
In the implementation below I also preferred to use setMarkup() over
overriding getMarkup(). It seems to me getMarkup() is not suitable to
be overwritten, as the rest of the code with Component seems to assume
it is an accessor to a field (hence multiple invocations are assumed
cheap. The last invocation I listed was just used to get a handle to
the MarkupStream). I would recommend making getMarkup() final, and
maybe change the javadoc comment in IMarkupResourceStreamProvider.
I tried to get a IMarkupResourceStreamProvider solution to work, but I
fail to see an obvious way to get the associated Markup of a panel
class implementing IMarkupResourceStreamProvider, all approaches I
tried ended up using the provided getMarkupResourceStream() method.
public class CustomMarkupFallback2MarkupContainer extends
GenericPanel<String> implements IMarkupCacheKeyProvider {
private boolean overrideMarkup = false;
public CustomMarkupFallback2MarkupContainer(String id, String
markupString) {
super(id);
if (markupString != null) {
setMarkup(Markup.of(markupString));
overrideMarkup = true;
}
}
/**
* For panels, the strategy by Panel.newMarkupSourcingStrategy()
overrules markup, reads associated markup in the end
* @return
*/
protected IMarkupSourcingStrategy newMarkupSourcingStrategy()
{
if (overrideMarkup) {
return DefaultMarkupSourcingStrategy.get();
}
return super.newMarkupSourcingStrategy();
}
/**
* Do not cache markup by wicket, null means no caching. must
implement IMarkupCacheKeyProvider
*/
@Override
public String getCacheKey(MarkupContainer container, Class<?>
containerClass) {
return null;
}
}
On Tue, Sep 16, 2014 at 2:28 PM, Thibault Kruse
<ti...@googlemail.com> wrote:
> I forgot to mention, for my solution to work, the associated markup
> file must not have tags outside the wicket:panel tags:
> <wicket:panel>
> Fallback works!
> </wicket:panel>
>
> as opposed to
>
> <?xml version="1.0" encoding="UTF-8"?>
> <html xmlns="http://www.w3.org/1999/xhtml"
> xmlns:wicket="http://wicket.apache.org">
> <body>
> <wicket:panel>
> Fallback works!
> </wicket:panel>
> </body>
> </html>
>
> So I guess I am still doing something wrong here.
>
> On Tue, Sep 16, 2014 at 12:28 PM, Thibault Kruse
> <ti...@googlemail.com> wrote:
>> So, I have a working solution like this:
>>
>> public class CustomMarkupFallbackMarkupContainer extends
>> WebMarkupContainer implements IMarkupCacheKeyProvider {
>> public CustomMarkupFallbackMarkupContainer(String id,
>> IModel<String> model) {super(id, model);}
>>
>> @Override
>> public IMarkupFragment getMarkup() {
>> String markupString = (String) getDefaultModelObject();
>> if (markupString == null) {
>> return getAssociatedMarkup();
>> } else {
>> return Markup.of(markupString);
>> }
>> }
>>
>> @Override public String getCacheKey(MarkupContainer container,
>> Class<?> containerClass) {return null;}
>> }
>>
>> Regarding the multiple invocations of getMarkup(), they also occur
>> when caching, and indeed they occur on every request (caching happens
>> only for the associated markup, I assume). The calls all happen inside
>> the same call to Component.internalRender()
>>
>> Invocations are:
>> 1: Component.internalRender():2309 // creating a MarkupStream only
>> used inside if block
>>
>> 2:
>> Component.internalRenderComponent():2472 // some duplicate code with
>> internalRender()
>> MarkupContainer.onRender(): 1496
>> Component.internalRender():2344
>>
>> 3:
>> Component.renderComponentTag():3961
>> Component.internalRenderComponent():2505
>> MarkupContainer.onRender(): 1496
>> Component.internalRender():2344
>>
>> 4:
>> Component.renderComponentTag():3961
>> AssociatedMarkupSourcingStrategy.renderAssociatedMarkup()
>> AssociatedMarkupSourcingStrategy.renderAssociatedMarkup()
>> PanelMarkupSourcingStrategy.onComponentTagBody():112
>> Component.internalRenderComponent():2514
>> MarkupContainer.onRender(): 1496
>> Component.internalRender():2344
>>
>>
>>
>> Regarding usage of onComponentTagBody(), that seems also valid, but
>> much deeper into the Wicket API than I would want to go, in particular
>> given there are recommended solutions in
>> http://wicket.apache.org/guide/guide/advanced.html#advanced_5 and the
>> javadoc.
>>
>> On Tue, Sep 16, 2014 at 12:00 PM, Andrea Del Bene <an...@gmail.com> wrote:
>>> Hi,
>>>
>>> I didn't dig to much into the code, but keep in mind that you are disabling
>>> markup caching in your example. This might explain why getMarkup is called
>>> three times.
>>> Anyway, in your specific case it might be better not to implement
>>> IMarkupCacheKeyProvider and IMarkupResourceStreamProvider, but simply
>>> override onComponentTagBody like this:
>>>
>>> @Override
>>> public void onComponentTagBody(MarkupStream markupStream, ComponentTag
>>> openTag) {
>>> if (getDefaultModelObject() == null) {
>>> super.onComponentTagBody(markupStream, openTag);
>>> }
>>> else {
>>>
>>> replaceComponentTagBody(markupStream, openTag, "<wicket:panel>it
>>> works</wicket:panel>");
>>> }
>>> }
>>>>
>>>> So debugging a bit, I find that I get hit by the
>>>> PanelMarkupSourcingStrategy. It seems it throws away the body markup
>>>> in favcor of the associated Markup. So I could advance one step by
>>>> extending WebMarkupContainer instead of Panel.
>>>>
>>>> I notice that when extending Panel, getMarkup() is being called 3
>>>> times in my example, before the result is being discarded.
>>>>
>>>> That seems like design smell. If users override getMarkup() with some
>>>> expensive operation, they should be able to rely on this being called
>>>> just once, and this only if the result is actually being used.
>>>>
>>>> On Tue, Sep 16, 2014 at 11:24 AM, Thibault Kruse
>>>> <ti...@googlemail.com> wrote:
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Programmatic Markup with fallback
Posted by Thibault Kruse <ti...@googlemail.com>.
I forgot to mention, for my solution to work, the associated markup
file must not have tags outside the wicket:panel tags:
<wicket:panel>
Fallback works!
</wicket:panel>
as opposed to
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
Fallback works!
</wicket:panel>
</body>
</html>
So I guess I am still doing something wrong here.
On Tue, Sep 16, 2014 at 12:28 PM, Thibault Kruse
<ti...@googlemail.com> wrote:
> So, I have a working solution like this:
>
> public class CustomMarkupFallbackMarkupContainer extends
> WebMarkupContainer implements IMarkupCacheKeyProvider {
> public CustomMarkupFallbackMarkupContainer(String id,
> IModel<String> model) {super(id, model);}
>
> @Override
> public IMarkupFragment getMarkup() {
> String markupString = (String) getDefaultModelObject();
> if (markupString == null) {
> return getAssociatedMarkup();
> } else {
> return Markup.of(markupString);
> }
> }
>
> @Override public String getCacheKey(MarkupContainer container,
> Class<?> containerClass) {return null;}
> }
>
> Regarding the multiple invocations of getMarkup(), they also occur
> when caching, and indeed they occur on every request (caching happens
> only for the associated markup, I assume). The calls all happen inside
> the same call to Component.internalRender()
>
> Invocations are:
> 1: Component.internalRender():2309 // creating a MarkupStream only
> used inside if block
>
> 2:
> Component.internalRenderComponent():2472 // some duplicate code with
> internalRender()
> MarkupContainer.onRender(): 1496
> Component.internalRender():2344
>
> 3:
> Component.renderComponentTag():3961
> Component.internalRenderComponent():2505
> MarkupContainer.onRender(): 1496
> Component.internalRender():2344
>
> 4:
> Component.renderComponentTag():3961
> AssociatedMarkupSourcingStrategy.renderAssociatedMarkup()
> AssociatedMarkupSourcingStrategy.renderAssociatedMarkup()
> PanelMarkupSourcingStrategy.onComponentTagBody():112
> Component.internalRenderComponent():2514
> MarkupContainer.onRender(): 1496
> Component.internalRender():2344
>
>
>
> Regarding usage of onComponentTagBody(), that seems also valid, but
> much deeper into the Wicket API than I would want to go, in particular
> given there are recommended solutions in
> http://wicket.apache.org/guide/guide/advanced.html#advanced_5 and the
> javadoc.
>
> On Tue, Sep 16, 2014 at 12:00 PM, Andrea Del Bene <an...@gmail.com> wrote:
>> Hi,
>>
>> I didn't dig to much into the code, but keep in mind that you are disabling
>> markup caching in your example. This might explain why getMarkup is called
>> three times.
>> Anyway, in your specific case it might be better not to implement
>> IMarkupCacheKeyProvider and IMarkupResourceStreamProvider, but simply
>> override onComponentTagBody like this:
>>
>> @Override
>> public void onComponentTagBody(MarkupStream markupStream, ComponentTag
>> openTag) {
>> if (getDefaultModelObject() == null) {
>> super.onComponentTagBody(markupStream, openTag);
>> }
>> else {
>>
>> replaceComponentTagBody(markupStream, openTag, "<wicket:panel>it
>> works</wicket:panel>");
>> }
>> }
>>>
>>> So debugging a bit, I find that I get hit by the
>>> PanelMarkupSourcingStrategy. It seems it throws away the body markup
>>> in favcor of the associated Markup. So I could advance one step by
>>> extending WebMarkupContainer instead of Panel.
>>>
>>> I notice that when extending Panel, getMarkup() is being called 3
>>> times in my example, before the result is being discarded.
>>>
>>> That seems like design smell. If users override getMarkup() with some
>>> expensive operation, they should be able to rely on this being called
>>> just once, and this only if the result is actually being used.
>>>
>>> On Tue, Sep 16, 2014 at 11:24 AM, Thibault Kruse
>>> <ti...@googlemail.com> wrote:
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Programmatic Markup with fallback
Posted by Thibault Kruse <ti...@googlemail.com>.
So, I have a working solution like this:
public class CustomMarkupFallbackMarkupContainer extends
WebMarkupContainer implements IMarkupCacheKeyProvider {
public CustomMarkupFallbackMarkupContainer(String id,
IModel<String> model) {super(id, model);}
@Override
public IMarkupFragment getMarkup() {
String markupString = (String) getDefaultModelObject();
if (markupString == null) {
return getAssociatedMarkup();
} else {
return Markup.of(markupString);
}
}
@Override public String getCacheKey(MarkupContainer container,
Class<?> containerClass) {return null;}
}
Regarding the multiple invocations of getMarkup(), they also occur
when caching, and indeed they occur on every request (caching happens
only for the associated markup, I assume). The calls all happen inside
the same call to Component.internalRender()
Invocations are:
1: Component.internalRender():2309 // creating a MarkupStream only
used inside if block
2:
Component.internalRenderComponent():2472 // some duplicate code with
internalRender()
MarkupContainer.onRender(): 1496
Component.internalRender():2344
3:
Component.renderComponentTag():3961
Component.internalRenderComponent():2505
MarkupContainer.onRender(): 1496
Component.internalRender():2344
4:
Component.renderComponentTag():3961
AssociatedMarkupSourcingStrategy.renderAssociatedMarkup()
AssociatedMarkupSourcingStrategy.renderAssociatedMarkup()
PanelMarkupSourcingStrategy.onComponentTagBody():112
Component.internalRenderComponent():2514
MarkupContainer.onRender(): 1496
Component.internalRender():2344
Regarding usage of onComponentTagBody(), that seems also valid, but
much deeper into the Wicket API than I would want to go, in particular
given there are recommended solutions in
http://wicket.apache.org/guide/guide/advanced.html#advanced_5 and the
javadoc.
On Tue, Sep 16, 2014 at 12:00 PM, Andrea Del Bene <an...@gmail.com> wrote:
> Hi,
>
> I didn't dig to much into the code, but keep in mind that you are disabling
> markup caching in your example. This might explain why getMarkup is called
> three times.
> Anyway, in your specific case it might be better not to implement
> IMarkupCacheKeyProvider and IMarkupResourceStreamProvider, but simply
> override onComponentTagBody like this:
>
> @Override
> public void onComponentTagBody(MarkupStream markupStream, ComponentTag
> openTag) {
> if (getDefaultModelObject() == null) {
> super.onComponentTagBody(markupStream, openTag);
> }
> else {
>
> replaceComponentTagBody(markupStream, openTag, "<wicket:panel>it
> works</wicket:panel>");
> }
> }
>>
>> So debugging a bit, I find that I get hit by the
>> PanelMarkupSourcingStrategy. It seems it throws away the body markup
>> in favcor of the associated Markup. So I could advance one step by
>> extending WebMarkupContainer instead of Panel.
>>
>> I notice that when extending Panel, getMarkup() is being called 3
>> times in my example, before the result is being discarded.
>>
>> That seems like design smell. If users override getMarkup() with some
>> expensive operation, they should be able to rely on this being called
>> just once, and this only if the result is actually being used.
>>
>> On Tue, Sep 16, 2014 at 11:24 AM, Thibault Kruse
>> <ti...@googlemail.com> wrote:
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Programmatic Markup with fallback
Posted by Andrea Del Bene <an...@gmail.com>.
Hi,
I didn't dig to much into the code, but keep in mind that you are
disabling markup caching in your example. This might explain why
getMarkup is called three times.
Anyway, in your specific case it might be better not to implement
IMarkupCacheKeyProvider and IMarkupResourceStreamProvider, but simply
override onComponentTagBody like this:
@Override
public void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag) {
if (getDefaultModelObject() == null) {
super.onComponentTagBody(markupStream, openTag);
}
else {
replaceComponentTagBody(markupStream, openTag,
"<wicket:panel>it works</wicket:panel>");
}
}
> So debugging a bit, I find that I get hit by the
> PanelMarkupSourcingStrategy. It seems it throws away the body markup
> in favcor of the associated Markup. So I could advance one step by
> extending WebMarkupContainer instead of Panel.
>
> I notice that when extending Panel, getMarkup() is being called 3
> times in my example, before the result is being discarded.
>
> That seems like design smell. If users override getMarkup() with some
> expensive operation, they should be able to rely on this being called
> just once, and this only if the result is actually being used.
>
> On Tue, Sep 16, 2014 at 11:24 AM, Thibault Kruse
> <ti...@googlemail.com> wrote:
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Programmatic Markup with fallback
Posted by Thibault Kruse <ti...@googlemail.com>.
So debugging a bit, I find that I get hit by the
PanelMarkupSourcingStrategy. It seems it throws away the body markup
in favcor of the associated Markup. So I could advance one step by
extending WebMarkupContainer instead of Panel.
I notice that when extending Panel, getMarkup() is being called 3
times in my example, before the result is being discarded.
That seems like design smell. If users override getMarkup() with some
expensive operation, they should be able to rely on this being called
just once, and this only if the result is actually being used.
On Tue, Sep 16, 2014 at 11:24 AM, Thibault Kruse
<ti...@googlemail.com> wrote:
> Regarding the markupException, the example I posted was flawed, must
> be: return Markup.of("<wicket:panel>it works</wicket:panel>");
> But that is not relevant to my report. The example on github had this fixed.
>
> Any other ideas / somewhat clean workaround? SHould I open a JIRA
> issue on this, or two?
>
> On Mon, Sep 15, 2014 at 8:01 PM, Thibault Kruse
> <ti...@googlemail.com> wrote:
>> Sorry, this was wicket 1.6.16 and 1.6.17.
>> Here is a quickstart, to reproduce both cases some comments have to be switched:
>> https://github.com/tkruse/custommarkup
>>
>> On Mon, Sep 15, 2014 at 7:50 PM, Sven Meier <sv...@meiers.net> wrote:
>>> Hi,
>>>
>>> which Wicket version?
>>>
>>> The first approach leads to a MarkupException here with Wicket 1.6.x.
>>>
>>> Regards
>>> Sven
>>>
>>>
>>> On 09/15/2014 07:37 PM, Thibault Kruse wrote:
>>>>
>>>> Hi,
>>>>
>>>> I am trying to create a wicket panel that renders markup from some
>>>> remote source, but if fetching fails, renders some fallback markup. I
>>>> want to achieve this with minimal code.
>>>>
>>>> I tried two approaches one based on overriding getMarkup(), one based
>>>> on http://wicket.apache.org/guide/guide/advanced.html#advanced_5, both
>>>> fail:
>>>>
>>>> /**
>>>> * attempts to use custom markup by overriding getMarkup()... but html is
>>>> used
>>>> */
>>>> public class CustomMarkupFallback1Panel extends GenericPanel<String> {
>>>> @Override
>>>> public IMarkupFragment getMarkup() {
>>>> return Markup.of("it works");
>>>> }
>>>> }
>>>>
>>>> CustomMarkupFallback1Panel.html:
>>>> <wicket:panel>
>>>> Fail!
>>>> </wicket:panel>
>>>>
>>>>
>>>> This first one overrides getMarkup() as suggested in the javadoc of
>>>> IMarkupResourceStreamProvider, but what gets rendered is instead the
>>>> static html (even though the debugger walks through getMarkup().
>>>>
>>>>
>>>> The second approach fails using IMarkupResourceStreamProvider works
>>>> for the intended markup, but not for the fallback markup
>>>> public class CustomMarkupFallback2Panel extends GenericPanel<String>
>>>> IMarkupResourceStreamProvider {
>>>>
>>>> @Override
>>>> public IResourceStream getMarkupResourceStream(MarkupContainer
>>>> container, Class<?> containerClass) {
>>>> if (getModelObject() == null) {
>>>> // thows Exception, see below. html file exists
>>>> return getMarkup().getMarkupResourceStream();
>>>> } else {
>>>> // works
>>>> return new StringResourceStream(getModelObject());
>>>> }
>>>> }
>>>> }
>>>>
>>>>
>>>> At least the first failure seems like a bug to me, not sure whether
>>>> the second approach is supposed to work, or how else to load markup
>>>> the wicket way.
>>>>
>>>> Is there maybe a completely different approach to achieve what I try to
>>>> do?
>>>>
>>>> cheers,
>>>> Thibault
>>>>
>>>>
>>>>
>>>> java.io.IOException: Stream closed
>>>> at
>>>> java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:162)
>>>> at java.io.BufferedInputStream.read(BufferedInputStream.java:325)
>>>> at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
>>>> at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
>>>> at
>>>> org.apache.wicket.util.io.BOMInputStream.getBOM(BOMInputStream.java:217)
>>>> at
>>>> org.apache.wicket.util.io.BOMInputStream.readFirstBytes(BOMInputStream.java:261)
>>>> at
>>>> org.apache.wicket.util.io.BOMInputStream.read(BOMInputStream.java:312)
>>>> at
>>>> org.apache.wicket.util.io.XmlReader.getXmlDeclaration(XmlReader.java:183)
>>>> at org.apache.wicket.util.io.XmlReader.init(XmlReader.java:106)
>>>> at org.apache.wicket.util.io.XmlReader.<init>(XmlReader.java:81)
>>>> at
>>>> org.apache.wicket.markup.parser.XmlPullParser.parse(XmlPullParser.java:605)
>>>> at
>>>> org.apache.wicket.markup.AbstractMarkupParser.parse(AbstractMarkupParser.java:178)
>>>> at
>>>> org.apache.wicket.markup.loader.SimpleMarkupLoader.loadMarkup(SimpleMarkupLoader.java:51)
>>>> at
>>>> org.apache.wicket.markup.loader.InheritedMarkupMarkupLoader.loadMarkup(InheritedMarkupMarkupLoader.java:57)
>>>> at
>>>> org.apache.wicket.markup.loader.DefaultMarkupLoader.loadMarkup(DefaultMarkupLoader.java:52)
>>>> at
>>>> org.apache.wicket.markup.MarkupFactory.loadMarkup(MarkupFactory.java:412)
>>>> at
>>>> org.apache.wicket.markup.MarkupCache.loadMarkup(MarkupCache.java:448)
>>>> at
>>>> org.apache.wicket.markup.MarkupCache.loadMarkupAndWatchForChanges(MarkupCache.java:544)
>>>> at
>>>> org.apache.wicket.markup.MarkupCache.getMarkup(MarkupCache.java:305)
>>>> at
>>>> org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:236)
>>>> at
>>>> org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:194)
>>>> at
>>>> org.apache.wicket.MarkupContainer.getAssociatedMarkup(MarkupContainer.java:405)
>>>> at
>>>> org.apache.wicket.MarkupContainer.getAssociatedMarkupStream(MarkupContainer.java:372)
>>>> at
>>>> org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHeadFromAssociatedMarkupFile(AssociatedMarkupSourcingStrategy.java:244)
>>>> at
>>>> org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHead(AssociatedMarkupSourcingStrategy.java:220)
>>>> at org.apache.wicket.Component.renderHead(Component.java:2652)
>>>> at
>>>> org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy$1.component(ChildFirstHeaderRenderStrategy.java:85)
>>>> at
>>>> org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:96)
>>>> at
>>>> org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:87)
>>>> at
>>>> org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:51)
>>>> at
>>>> org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderChildHeaders(ChildFirstHeaderRenderStrategy.java:78)
>>>> at
>>>> org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderHeader(ChildFirstHeaderRenderStrategy.java:57)
>>>> at
>>>> org.apache.wicket.markup.html.internal.HtmlHeaderContainer.onComponentTagBody(HtmlHeaderContainer.java:170)
>>>> at
>>>> org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71)
>>>> at
>>>> org.apache.wicket.Component.internalRenderComponent(Component.java:2514)
>>>> at
>>>> org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1496)
>>>> at org.apache.wicket.Component.internalRender(Component.java:2344)
>>>> at org.apache.wicket.Component.render(Component.java:2272)
>>>> at
>>>> org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1392)
>>>> at
>>>> org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1557)
>>>> at org.apache.wicket.Page.onRender(Page.java:887)
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Programmatic Markup with fallback
Posted by Thibault Kruse <ti...@googlemail.com>.
Regarding the markupException, the example I posted was flawed, must
be: return Markup.of("<wicket:panel>it works</wicket:panel>");
But that is not relevant to my report. The example on github had this fixed.
Any other ideas / somewhat clean workaround? SHould I open a JIRA
issue on this, or two?
On Mon, Sep 15, 2014 at 8:01 PM, Thibault Kruse
<ti...@googlemail.com> wrote:
> Sorry, this was wicket 1.6.16 and 1.6.17.
> Here is a quickstart, to reproduce both cases some comments have to be switched:
> https://github.com/tkruse/custommarkup
>
> On Mon, Sep 15, 2014 at 7:50 PM, Sven Meier <sv...@meiers.net> wrote:
>> Hi,
>>
>> which Wicket version?
>>
>> The first approach leads to a MarkupException here with Wicket 1.6.x.
>>
>> Regards
>> Sven
>>
>>
>> On 09/15/2014 07:37 PM, Thibault Kruse wrote:
>>>
>>> Hi,
>>>
>>> I am trying to create a wicket panel that renders markup from some
>>> remote source, but if fetching fails, renders some fallback markup. I
>>> want to achieve this with minimal code.
>>>
>>> I tried two approaches one based on overriding getMarkup(), one based
>>> on http://wicket.apache.org/guide/guide/advanced.html#advanced_5, both
>>> fail:
>>>
>>> /**
>>> * attempts to use custom markup by overriding getMarkup()... but html is
>>> used
>>> */
>>> public class CustomMarkupFallback1Panel extends GenericPanel<String> {
>>> @Override
>>> public IMarkupFragment getMarkup() {
>>> return Markup.of("it works");
>>> }
>>> }
>>>
>>> CustomMarkupFallback1Panel.html:
>>> <wicket:panel>
>>> Fail!
>>> </wicket:panel>
>>>
>>>
>>> This first one overrides getMarkup() as suggested in the javadoc of
>>> IMarkupResourceStreamProvider, but what gets rendered is instead the
>>> static html (even though the debugger walks through getMarkup().
>>>
>>>
>>> The second approach fails using IMarkupResourceStreamProvider works
>>> for the intended markup, but not for the fallback markup
>>> public class CustomMarkupFallback2Panel extends GenericPanel<String>
>>> IMarkupResourceStreamProvider {
>>>
>>> @Override
>>> public IResourceStream getMarkupResourceStream(MarkupContainer
>>> container, Class<?> containerClass) {
>>> if (getModelObject() == null) {
>>> // thows Exception, see below. html file exists
>>> return getMarkup().getMarkupResourceStream();
>>> } else {
>>> // works
>>> return new StringResourceStream(getModelObject());
>>> }
>>> }
>>> }
>>>
>>>
>>> At least the first failure seems like a bug to me, not sure whether
>>> the second approach is supposed to work, or how else to load markup
>>> the wicket way.
>>>
>>> Is there maybe a completely different approach to achieve what I try to
>>> do?
>>>
>>> cheers,
>>> Thibault
>>>
>>>
>>>
>>> java.io.IOException: Stream closed
>>> at
>>> java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:162)
>>> at java.io.BufferedInputStream.read(BufferedInputStream.java:325)
>>> at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
>>> at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
>>> at
>>> org.apache.wicket.util.io.BOMInputStream.getBOM(BOMInputStream.java:217)
>>> at
>>> org.apache.wicket.util.io.BOMInputStream.readFirstBytes(BOMInputStream.java:261)
>>> at
>>> org.apache.wicket.util.io.BOMInputStream.read(BOMInputStream.java:312)
>>> at
>>> org.apache.wicket.util.io.XmlReader.getXmlDeclaration(XmlReader.java:183)
>>> at org.apache.wicket.util.io.XmlReader.init(XmlReader.java:106)
>>> at org.apache.wicket.util.io.XmlReader.<init>(XmlReader.java:81)
>>> at
>>> org.apache.wicket.markup.parser.XmlPullParser.parse(XmlPullParser.java:605)
>>> at
>>> org.apache.wicket.markup.AbstractMarkupParser.parse(AbstractMarkupParser.java:178)
>>> at
>>> org.apache.wicket.markup.loader.SimpleMarkupLoader.loadMarkup(SimpleMarkupLoader.java:51)
>>> at
>>> org.apache.wicket.markup.loader.InheritedMarkupMarkupLoader.loadMarkup(InheritedMarkupMarkupLoader.java:57)
>>> at
>>> org.apache.wicket.markup.loader.DefaultMarkupLoader.loadMarkup(DefaultMarkupLoader.java:52)
>>> at
>>> org.apache.wicket.markup.MarkupFactory.loadMarkup(MarkupFactory.java:412)
>>> at
>>> org.apache.wicket.markup.MarkupCache.loadMarkup(MarkupCache.java:448)
>>> at
>>> org.apache.wicket.markup.MarkupCache.loadMarkupAndWatchForChanges(MarkupCache.java:544)
>>> at
>>> org.apache.wicket.markup.MarkupCache.getMarkup(MarkupCache.java:305)
>>> at
>>> org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:236)
>>> at
>>> org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:194)
>>> at
>>> org.apache.wicket.MarkupContainer.getAssociatedMarkup(MarkupContainer.java:405)
>>> at
>>> org.apache.wicket.MarkupContainer.getAssociatedMarkupStream(MarkupContainer.java:372)
>>> at
>>> org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHeadFromAssociatedMarkupFile(AssociatedMarkupSourcingStrategy.java:244)
>>> at
>>> org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHead(AssociatedMarkupSourcingStrategy.java:220)
>>> at org.apache.wicket.Component.renderHead(Component.java:2652)
>>> at
>>> org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy$1.component(ChildFirstHeaderRenderStrategy.java:85)
>>> at
>>> org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:96)
>>> at
>>> org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:87)
>>> at
>>> org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:51)
>>> at
>>> org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderChildHeaders(ChildFirstHeaderRenderStrategy.java:78)
>>> at
>>> org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderHeader(ChildFirstHeaderRenderStrategy.java:57)
>>> at
>>> org.apache.wicket.markup.html.internal.HtmlHeaderContainer.onComponentTagBody(HtmlHeaderContainer.java:170)
>>> at
>>> org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71)
>>> at
>>> org.apache.wicket.Component.internalRenderComponent(Component.java:2514)
>>> at
>>> org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1496)
>>> at org.apache.wicket.Component.internalRender(Component.java:2344)
>>> at org.apache.wicket.Component.render(Component.java:2272)
>>> at
>>> org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1392)
>>> at
>>> org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1557)
>>> at org.apache.wicket.Page.onRender(Page.java:887)
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Programmatic Markup with fallback
Posted by Thibault Kruse <ti...@googlemail.com>.
Sorry, this was wicket 1.6.16 and 1.6.17.
Here is a quickstart, to reproduce both cases some comments have to be switched:
https://github.com/tkruse/custommarkup
On Mon, Sep 15, 2014 at 7:50 PM, Sven Meier <sv...@meiers.net> wrote:
> Hi,
>
> which Wicket version?
>
> The first approach leads to a MarkupException here with Wicket 1.6.x.
>
> Regards
> Sven
>
>
> On 09/15/2014 07:37 PM, Thibault Kruse wrote:
>>
>> Hi,
>>
>> I am trying to create a wicket panel that renders markup from some
>> remote source, but if fetching fails, renders some fallback markup. I
>> want to achieve this with minimal code.
>>
>> I tried two approaches one based on overriding getMarkup(), one based
>> on http://wicket.apache.org/guide/guide/advanced.html#advanced_5, both
>> fail:
>>
>> /**
>> * attempts to use custom markup by overriding getMarkup()... but html is
>> used
>> */
>> public class CustomMarkupFallback1Panel extends GenericPanel<String> {
>> @Override
>> public IMarkupFragment getMarkup() {
>> return Markup.of("it works");
>> }
>> }
>>
>> CustomMarkupFallback1Panel.html:
>> <wicket:panel>
>> Fail!
>> </wicket:panel>
>>
>>
>> This first one overrides getMarkup() as suggested in the javadoc of
>> IMarkupResourceStreamProvider, but what gets rendered is instead the
>> static html (even though the debugger walks through getMarkup().
>>
>>
>> The second approach fails using IMarkupResourceStreamProvider works
>> for the intended markup, but not for the fallback markup
>> public class CustomMarkupFallback2Panel extends GenericPanel<String>
>> IMarkupResourceStreamProvider {
>>
>> @Override
>> public IResourceStream getMarkupResourceStream(MarkupContainer
>> container, Class<?> containerClass) {
>> if (getModelObject() == null) {
>> // thows Exception, see below. html file exists
>> return getMarkup().getMarkupResourceStream();
>> } else {
>> // works
>> return new StringResourceStream(getModelObject());
>> }
>> }
>> }
>>
>>
>> At least the first failure seems like a bug to me, not sure whether
>> the second approach is supposed to work, or how else to load markup
>> the wicket way.
>>
>> Is there maybe a completely different approach to achieve what I try to
>> do?
>>
>> cheers,
>> Thibault
>>
>>
>>
>> java.io.IOException: Stream closed
>> at
>> java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:162)
>> at java.io.BufferedInputStream.read(BufferedInputStream.java:325)
>> at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
>> at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
>> at
>> org.apache.wicket.util.io.BOMInputStream.getBOM(BOMInputStream.java:217)
>> at
>> org.apache.wicket.util.io.BOMInputStream.readFirstBytes(BOMInputStream.java:261)
>> at
>> org.apache.wicket.util.io.BOMInputStream.read(BOMInputStream.java:312)
>> at
>> org.apache.wicket.util.io.XmlReader.getXmlDeclaration(XmlReader.java:183)
>> at org.apache.wicket.util.io.XmlReader.init(XmlReader.java:106)
>> at org.apache.wicket.util.io.XmlReader.<init>(XmlReader.java:81)
>> at
>> org.apache.wicket.markup.parser.XmlPullParser.parse(XmlPullParser.java:605)
>> at
>> org.apache.wicket.markup.AbstractMarkupParser.parse(AbstractMarkupParser.java:178)
>> at
>> org.apache.wicket.markup.loader.SimpleMarkupLoader.loadMarkup(SimpleMarkupLoader.java:51)
>> at
>> org.apache.wicket.markup.loader.InheritedMarkupMarkupLoader.loadMarkup(InheritedMarkupMarkupLoader.java:57)
>> at
>> org.apache.wicket.markup.loader.DefaultMarkupLoader.loadMarkup(DefaultMarkupLoader.java:52)
>> at
>> org.apache.wicket.markup.MarkupFactory.loadMarkup(MarkupFactory.java:412)
>> at
>> org.apache.wicket.markup.MarkupCache.loadMarkup(MarkupCache.java:448)
>> at
>> org.apache.wicket.markup.MarkupCache.loadMarkupAndWatchForChanges(MarkupCache.java:544)
>> at
>> org.apache.wicket.markup.MarkupCache.getMarkup(MarkupCache.java:305)
>> at
>> org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:236)
>> at
>> org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:194)
>> at
>> org.apache.wicket.MarkupContainer.getAssociatedMarkup(MarkupContainer.java:405)
>> at
>> org.apache.wicket.MarkupContainer.getAssociatedMarkupStream(MarkupContainer.java:372)
>> at
>> org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHeadFromAssociatedMarkupFile(AssociatedMarkupSourcingStrategy.java:244)
>> at
>> org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHead(AssociatedMarkupSourcingStrategy.java:220)
>> at org.apache.wicket.Component.renderHead(Component.java:2652)
>> at
>> org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy$1.component(ChildFirstHeaderRenderStrategy.java:85)
>> at
>> org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:96)
>> at
>> org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:87)
>> at
>> org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:51)
>> at
>> org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderChildHeaders(ChildFirstHeaderRenderStrategy.java:78)
>> at
>> org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderHeader(ChildFirstHeaderRenderStrategy.java:57)
>> at
>> org.apache.wicket.markup.html.internal.HtmlHeaderContainer.onComponentTagBody(HtmlHeaderContainer.java:170)
>> at
>> org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71)
>> at
>> org.apache.wicket.Component.internalRenderComponent(Component.java:2514)
>> at
>> org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1496)
>> at org.apache.wicket.Component.internalRender(Component.java:2344)
>> at org.apache.wicket.Component.render(Component.java:2272)
>> at
>> org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1392)
>> at
>> org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1557)
>> at org.apache.wicket.Page.onRender(Page.java:887)
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Programmatic Markup with fallback
Posted by Sven Meier <sv...@meiers.net>.
Hi,
which Wicket version?
The first approach leads to a MarkupException here with Wicket 1.6.x.
Regards
Sven
On 09/15/2014 07:37 PM, Thibault Kruse wrote:
> Hi,
>
> I am trying to create a wicket panel that renders markup from some
> remote source, but if fetching fails, renders some fallback markup. I
> want to achieve this with minimal code.
>
> I tried two approaches one based on overriding getMarkup(), one based
> on http://wicket.apache.org/guide/guide/advanced.html#advanced_5, both
> fail:
>
> /**
> * attempts to use custom markup by overriding getMarkup()... but html is used
> */
> public class CustomMarkupFallback1Panel extends GenericPanel<String> {
> @Override
> public IMarkupFragment getMarkup() {
> return Markup.of("it works");
> }
> }
>
> CustomMarkupFallback1Panel.html:
> <wicket:panel>
> Fail!
> </wicket:panel>
>
>
> This first one overrides getMarkup() as suggested in the javadoc of
> IMarkupResourceStreamProvider, but what gets rendered is instead the
> static html (even though the debugger walks through getMarkup().
>
>
> The second approach fails using IMarkupResourceStreamProvider works
> for the intended markup, but not for the fallback markup
> public class CustomMarkupFallback2Panel extends GenericPanel<String>
> IMarkupResourceStreamProvider {
>
> @Override
> public IResourceStream getMarkupResourceStream(MarkupContainer
> container, Class<?> containerClass) {
> if (getModelObject() == null) {
> // thows Exception, see below. html file exists
> return getMarkup().getMarkupResourceStream();
> } else {
> // works
> return new StringResourceStream(getModelObject());
> }
> }
> }
>
>
> At least the first failure seems like a bug to me, not sure whether
> the second approach is supposed to work, or how else to load markup
> the wicket way.
>
> Is there maybe a completely different approach to achieve what I try to do?
>
> cheers,
> Thibault
>
>
>
> java.io.IOException: Stream closed
> at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:162)
> at java.io.BufferedInputStream.read(BufferedInputStream.java:325)
> at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
> at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
> at org.apache.wicket.util.io.BOMInputStream.getBOM(BOMInputStream.java:217)
> at org.apache.wicket.util.io.BOMInputStream.readFirstBytes(BOMInputStream.java:261)
> at org.apache.wicket.util.io.BOMInputStream.read(BOMInputStream.java:312)
> at org.apache.wicket.util.io.XmlReader.getXmlDeclaration(XmlReader.java:183)
> at org.apache.wicket.util.io.XmlReader.init(XmlReader.java:106)
> at org.apache.wicket.util.io.XmlReader.<init>(XmlReader.java:81)
> at org.apache.wicket.markup.parser.XmlPullParser.parse(XmlPullParser.java:605)
> at org.apache.wicket.markup.AbstractMarkupParser.parse(AbstractMarkupParser.java:178)
> at org.apache.wicket.markup.loader.SimpleMarkupLoader.loadMarkup(SimpleMarkupLoader.java:51)
> at org.apache.wicket.markup.loader.InheritedMarkupMarkupLoader.loadMarkup(InheritedMarkupMarkupLoader.java:57)
> at org.apache.wicket.markup.loader.DefaultMarkupLoader.loadMarkup(DefaultMarkupLoader.java:52)
> at org.apache.wicket.markup.MarkupFactory.loadMarkup(MarkupFactory.java:412)
> at org.apache.wicket.markup.MarkupCache.loadMarkup(MarkupCache.java:448)
> at org.apache.wicket.markup.MarkupCache.loadMarkupAndWatchForChanges(MarkupCache.java:544)
> at org.apache.wicket.markup.MarkupCache.getMarkup(MarkupCache.java:305)
> at org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:236)
> at org.apache.wicket.markup.MarkupFactory.getMarkup(MarkupFactory.java:194)
> at org.apache.wicket.MarkupContainer.getAssociatedMarkup(MarkupContainer.java:405)
> at org.apache.wicket.MarkupContainer.getAssociatedMarkupStream(MarkupContainer.java:372)
> at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHeadFromAssociatedMarkupFile(AssociatedMarkupSourcingStrategy.java:244)
> at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderHead(AssociatedMarkupSourcingStrategy.java:220)
> at org.apache.wicket.Component.renderHead(Component.java:2652)
> at org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy$1.component(ChildFirstHeaderRenderStrategy.java:85)
> at org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:96)
> at org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:87)
> at org.apache.wicket.markup.renderStrategy.DeepChildFirstVisitor.visit(DeepChildFirstVisitor.java:51)
> at org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderChildHeaders(ChildFirstHeaderRenderStrategy.java:78)
> at org.apache.wicket.markup.renderStrategy.ChildFirstHeaderRenderStrategy.renderHeader(ChildFirstHeaderRenderStrategy.java:57)
> at org.apache.wicket.markup.html.internal.HtmlHeaderContainer.onComponentTagBody(HtmlHeaderContainer.java:170)
> at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71)
> at org.apache.wicket.Component.internalRenderComponent(Component.java:2514)
> at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1496)
> at org.apache.wicket.Component.internalRender(Component.java:2344)
> at org.apache.wicket.Component.render(Component.java:2272)
> at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1392)
> at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1557)
> at org.apache.wicket.Page.onRender(Page.java:887)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org