I had a similar case where I wanted to contribute header sections that
are written with renderString() last. I was not able to figure out all
that resource aggregation and bucketing stuff, so I wrote something
simpler. I would appreciate if somebody could review and comment on
this:
setHeaderResponseDecorator(new IHeaderResponseDecorator()
{
@Override
public IHeaderResponse decorate(IHeaderResponse response) {
return new DecoratingHeaderResponse(response)
{
private CharSequence stringToRender;
@Override
public void renderString(CharSequence string) {
stringToRender = stringToRender == null ?
string : stringToRender.toString() + string;
}
@Override
public void close() {
renderStringIfNeeded();
super.close();
}
private void renderStringIfNeeded() {
if (stringToRender != null &&
!wasRendered(stringToRender)) {
super.renderString(stringToRender);
markRendered(stringToRender);
}
}
};
}
});
On Fri, Jul 22, 2011 at 12:28 AM, Martin Grigorov <[email protected]> wrote:
> Hi,
>
> It is not documented by <wicket:head> contributes before
> #renderHead(). This may change in the future so don't rely on it.
> Better take a look at
> http://wicketstuff.org/wicket/resourceaggregation application. There
> you can see how resources are scored. This way you can setup
> org.apache.wicket.resource.filtering.HeaderResponseContainerFilteringHeaderResponse.IHeaderResponseFilter
> which renders your specific contribution after all other.
> To render CSS text use
> org.apache.wicket.markup.html.IHeaderResponse.renderCSS(CharSequence
> css, String id). Use the id in the filter to recognize it.
>
> On Fri, Jul 22, 2011 at 1:00 AM, Loren Cole <[email protected]> wrote:
>> Under normal circumstances I would, but I don't have my css in a file. It
>> gets pulled from a database and stashed in the session. All the header
>> contributer classes and resource references assume there's a file somewhere
>> with this info. But in my case there is not.
>>
>> And, even id I did stuff this data into a file it still wouldn't fix my
>> problem, because the customer defined css needs to override everything else
>> with the same css selector. If another component added a header contributor
>> afterwards that would not be the case.
>>
>> -
>> Loren
>>
>> On Tue, Jul 19, 2011 at 11:35 PM, Jeremy Thomerson <
>> [email protected]> wrote:
>>
>>> To start, don't use a Label to contribute css. Use a header contributor.
>>> That's what they're made for.
>>> On 2011 7 19 13:22, "Loren Cole" <[email protected]> wrote:
>>> > We're making our application skinable, but I'm having some trouble
>>> getting
>>> > user specified css into the right place in the header. We're working in a
>>> > distributed environment, so instead of saving their css in the file
>>> system
>>> > we're putting it in our database, and in order to get the cascade to work
>>> > properly we need to add this css after all the others. Here's how I'm
>>> > adding it:
>>> >
>>> > StandardPage.java
>>> >
>>> > onInitialize()
>>> > //Add any override style
>>> > Tenant tenant = MyWebSession.get().getTenant();
>>> > Css css = cssRepository.GetStyleByTenant(tenant);
>>> > if(tenant.getBranding() && css != null) {
>>> > add(new Label("style", css.getStyle()));
>>> > }
>>> > }
>>> >
>>> > StandardPage.html
>>> >
>>> > <wicket:head>
>>> > <style type="text/css" wicket:id="style"></style>
>>> > </wicket:head>
>>> >
>>> > -----------------------------------------
>>> > So the issue is that thet style tag comes before all my header
>>> > contributions. I've tried specifying a header response decorator like so:
>>> >
>>> > Application.java
>>> >
>>> > public static final String HEADER_FILTER_NAME = "myHeaderBucket";
>>> >
>>> > init() {
>>> > super.init();
>>> > setHeaderResponseDecorator(new IHeaderResponseDecorator() {
>>> >
>>> > HeaderResponseContainerFilteringHeaderResponse.IHeaderResponseFilter[]
>>> > filters = {new CssAcceptingHeaderResponseFilter(HEADER_FILTER_NAME)};
>>> > @Override
>>> > public IHeaderResponse decorate(IHeaderResponse response) {
>>> > return new
>>> > HeaderResponseContainerFilteringHeaderResponse(response,
>>> HEADER_FILTER_NAME,
>>> > filters);
>>> > }
>>> > });
>>> > }
>>> >
>>> > StandardPage.html
>>> >
>>> > <wicket:head>
>>> > <div wicket:id="myHeaderBucket"></div>
>>> > <style type="text/css" wicket:id="style"></style>
>>> > </wicket:head>
>>> >
>>> > ------------------------------
>>> >
>>> > Unfortunately I'm getting this exception when I instantiate a page:
>>> >
>>> > 12:28:04,097 INFO [STDOUT] 2011-07-19 12:28:04.096
>>> [http-127.0.0.1-8080-1]
>>> > [127.0.0.1] [T:2] [U:3 - joe_sharp]
>>> > [com.transverse.bleep.wicket.desktop.DesktopPage] ERROR
>>> > org.apache.wicket.RequestCycle 1529 - Exception in rendering component:
>>> > [MarkupContainer [Component id = headerBucket]]
>>> > org.apache.wicket.WicketRuntimeException: Exception in rendering
>>> component:
>>> > [MarkupContainer [Component id = headerBucket]]
>>> > at org.apache.wicket.Component.renderComponent(Component.java:2729)
>>> > ~[wicket-1.4.17.jar:1.4.17]
>>> > at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1539)
>>> > ~[wicket-1.4.17.jar:1.4.17]
>>> > at org.apache.wicket.Component.render(Component.java:2521)
>>> > ~[wicket-1.4.17.jar:1.4.17]
>>> > ...
>>> > Caused by: java.lang.RuntimeException: there was an error processing the
>>> > header response - you tried to render a bucket of response from
>>> > HeaderResponseContainerFilteringHeaderResponse, but it had not yet run
>>> and
>>> > been closed. this should occur when the header container that is standard
>>> > in wicket renders, so perhaps you have done something to keep that from
>>> > rendering?
>>> > at
>>> >
>>>
>>> org.apache.wicket.resource.filtering.HeaderResponseFilteredResponseContainer.onComponentTagBody(HeaderResponseFilteredResponseContainer.java:67)
>>> > ~[wicket-1.4.17.jar:1.4.17]
>>> > at org.apache.wicket.Component.renderComponent(Component.java:2690)
>>> > ~[wicket-1.4.17.jar:1.4.17]
>>> > ... 81 common frames omitted
>>> >
>>> >
>>> > Any ideas on what I'm doing wrong? Is there an easier approach I can
>>> take?
>>> >
>>> > Thanks,
>>> > Loren
>>>
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]