You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by heikki <tr...@gmail.com> on 2012/05/03 15:10:38 UTC

How to prevent duplicates when using HeaderContributor

hello,

I'd like to be able to use a fixed title for my pages, that gets overridden
for some of the pages.

To do that, I have a fixed title element in my base HTML page:


Then in the pages that should have a different title, I override
renderHead() like this:

    @Override
    public void renderHead(final IHeaderResponse response) {
        String title = "<title>" + getTheDynamicTitle() + "</title>";
        response.renderString(title);
   }

The result is that my rendered page has 2 <title> elements in its header,
the fixed one and the dynamic one.

I would have thought that Wicket would be smart enough to replace an
existing header element; the IHeaderResponse javadoc says "Implementation of
this interface is responsible for filtering duplicate contributions (so that
for example the same javascript is not loaded twice) during the same
request". Well. 

Do I need to write my own implementation of IHeaderResponse for this ? 

It would seem like a pretty common use case to me, did anyone already solve
it ?

Kind regards
Heikki Doeleman

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-prevent-duplicates-when-using-HeaderContributor-tp4605975.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to prevent duplicates when using HeaderContributor

Posted by heikki <tr...@gmail.com>.
OK, that's a good solution, thanks !

Just in case that quickstart becomes unavailable, for reference I'll
summarize the method here:

the base HTML page has 



The corresponding base Java class has



and any pages with an overridden title, override getTitle() 




Kind regards
Heikki Doeleman

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-prevent-duplicates-when-using-HeaderContributor-tp4605975p4606959.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to prevent duplicates when using HeaderContributor

Posted by Thomas Götz <to...@decoded.de>.
Please see the following quickstart for an example: http://cl.ly/0w421o340J2e2w330Y0j

Cheers,
   -Tom


On 03.05.2012 at 15:17 Christoph Leiter wrote:

> Hi,
> 
> the Javadoc of IHeaderResponse#renderString says:
> "Renders an arbitrary string to the header. The string is only rendered if the same string hasn't been rendered before."
> So if you call it with two different titles the expected behavior is to get the title tag twice.
> 
> I wouldn't use a IHeaderResponse for that. My suggestion is to use a normal title tag in your base page markup. Provide a method which returns the current title and let specific pages override that method as needed.
> 
> 
> Christoph
> 
> 
> 
> heikki (2012-05-03 15:10):
>> hello,
>> 
>> I'd like to be able to use a fixed title for my pages, that gets overridden
>> for some of the pages.
>> 
>> To do that, I have a fixed title element in my base HTML page:
>> 
>> 
>> Then in the pages that should have a different title, I override
>> renderHead() like this:
>> 
>>     @Override
>>     public void renderHead(final IHeaderResponse response) {
>>         String title = "<title>" + getTheDynamicTitle() +"</title>";
>>         response.renderString(title);
>>    }
>> 
>> The result is that my rendered page has 2<title>  elements in its header,
>> the fixed one and the dynamic one.
>> 
>> I would have thought that Wicket would be smart enough to replace an
>> existing header element; the IHeaderResponse javadoc says "Implementation of
>> this interface is responsible for filtering duplicate contributions (so that
>> for example the same javascript is not loaded twice) during the same
>> request". Well.
>> 
>> Do I need to write my own implementation of IHeaderResponse for this ?
>> 
>> It would seem like a pretty common use case to me, did anyone already solve
>> it ?
>> 
>> Kind regards
>> Heikki Doeleman
>> 
>> --
>> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-prevent-duplicates-when-using-HeaderContributor-tp4605975.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>> 
>> ---------------------------------------------------------------------
>> 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: How to prevent duplicates when using HeaderContributor

Posted by Christoph Leiter <ma...@christophleiter.com>.
Hi,

the Javadoc of IHeaderResponse#renderString says:
"Renders an arbitrary string to the header. The string is only rendered 
if the same string hasn't been rendered before."
So if you call it with two different titles the expected behavior is to 
get the title tag twice.

I wouldn't use a IHeaderResponse for that. My suggestion is to use a 
normal title tag in your base page markup. Provide a method which 
returns the current title and let specific pages override that method as 
needed.


Christoph



heikki (2012-05-03 15:10):
> hello,
>
> I'd like to be able to use a fixed title for my pages, that gets overridden
> for some of the pages.
>
> To do that, I have a fixed title element in my base HTML page:
>
>
> Then in the pages that should have a different title, I override
> renderHead() like this:
>
>      @Override
>      public void renderHead(final IHeaderResponse response) {
>          String title = "<title>" + getTheDynamicTitle() +"</title>";
>          response.renderString(title);
>     }
>
> The result is that my rendered page has 2<title>  elements in its header,
> the fixed one and the dynamic one.
>
> I would have thought that Wicket would be smart enough to replace an
> existing header element; the IHeaderResponse javadoc says "Implementation of
> this interface is responsible for filtering duplicate contributions (so that
> for example the same javascript is not loaded twice) during the same
> request". Well.
>
> Do I need to write my own implementation of IHeaderResponse for this ?
>
> It would seem like a pretty common use case to me, did anyone already solve
> it ?
>
> Kind regards
> Heikki Doeleman
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-prevent-duplicates-when-using-HeaderContributor-tp4605975.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> 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