You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris Colman <ch...@stepaheadsoftware.com> on 2012/04/01 23:16:56 UTC

Writing to header causes 'not yet working' code to be executed

I've overridden renderHead to write to the header of the page but I get
a strange error message that I have not been able to work out. It
executes some code that has a 'not implemented' comment:
 
The code is in WebPage:
 
            /**
             * Validate that each component which wanted to contribute
to the header section actually was
             * able to do so.
             */
            private void validateHeaders()
            {
                        // search for HtmlHeaderContainer in the first
level of children or deeper
                        // if there are transparent resolvers used
                        HtmlHeaderContainer header = visitChildren(new
IVisitor<Component, HtmlHeaderContainer>()
                        {
                                    public void component(final
Component component, final IVisit<HtmlHeaderContainer> visit)
                                    {
                                                if (component instanceof
HtmlHeaderContainer)
                                                {
 
visit.stop((HtmlHeaderContainer)component);
                                                }
                                                else if (component
instanceof TransparentWebMarkupContainer == false)
                                                {
 
visit.dontGoDeeper();
                                                }
                                    }
                        });
 
                        if (header == null)
                        {
                                    // the markup must at least contain
a <body> tag for wicket to automatically
                                    // create a HtmlHeaderContainer. Log
an error if no header container
                                    // was created but any of the
components or behaviors want to contribute
                                    // something to the header.
                                    header = new
HtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID);
                                    add(header);
 
                                    Response orgResponse =
getRequestCycle().getResponse();
                                    try
                                    {
                                                final StringResponse
response = new StringResponse();
 
getRequestCycle().setResponse(response);
 
                                                // Render all header
sections of all components on the page
 
AbstractHeaderRenderStrategy.get().renderHeader(header, getPage());
                                                response.close();
 
                                                if
(response.getBuffer().length() > 0)
                                                {
                                                            // @TODO it
is not yet working properly. JDo to fix it
 
log.error("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
 
log.error("You probably forgot to add a <body> or <head> tag to your
markup since no Header Container was \n" +
 
"found but components were found which want to write to the <head>
section.\n" +
 
response.getBuffer());
 
log.error("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
                                                }
                                    }
                                    catch (Exception e)
                                    {
                                                // just swallow this
exception, there isn't much we can do about.
                                                log.error("header/body
check throws exception", e);
                                    }
                                    finally
                                    {
                                                this.remove(header);
 
getRequestCycle().setResponse(orgResponse);
                                    }
                        }
            }
 
Yours sincerely,
 
Chris Colman
 
Pagebloom Team Leader,
Step Ahead Software

 
pagebloom - your business & your website growing together
 
Sydney: (+61 2) 9656 1278     Canberra: (+61 2) 6100 2120     
Email: chrisc@stepahead.com.au <ma...@stepahead.com.au> 
Website:
http://www.pagebloom.com <blocked::http://www.pagebloom.com/> 
http://develop.stepaheadsoftware.com
<blocked::http://develop.stepaheadsoftware.com/> 
 
 

RE: Writing to header causes 'not yet working' code to be executed

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
The strange thing is - I do have a <head> in my markup!

And it appears to render to the head section ok most of the time even
though it displays the message.

It really only fails, in a functional way, when I call
response.renderString twice within the renderHead method:

void renderHead
{
	super.renderHead(response);

	// Canonical URL
	String canonicalUrl = getCanonicalUrl();
	if ( !StringUtils.isEmpty(canonicalUrl) )
		response.renderString("<link rel=\"canonical\" href=\""
+ canonicalUrl + "\" />");  // If this line is not executed then head
render works but still displays message.

	// GoogleTrackingCode
	WebsiteMgr websiteMgr = getWebsiteMgr();

	if (websiteMgr != null)
	{
		String trackingHeadCode = websiteMgr.getEndBodyCode();
        
        if ( !StringUtils.isEmpty(trackingHeadCode))
            response.renderString(trackingHeadCode);
	}
}

>-----Original Message-----
>From: Martin Grigorov [mailto:mgrigorov@apache.org]
>Sent: Monday, 2 April 2012 4:58 PM
>To: users@wicket.apache.org
>Subject: Re: Writing to header causes 'not yet working' code to be
executed
>
>Hi,
>
>Can you create a quickstart ?
>There is a special IMarkupFilter that creates <head> automatically if
you
>don't have one in your page markup. For some reason it seems it didn't
>work.
>
>On Sun, Apr 1, 2012 at 11:16 PM, Chris Colman
><ch...@stepaheadsoftware.com>wrote:
>
>> ** **
>>
>> I've overridden renderHead to write to the header of the page but I
get a
>> strange error message that I have not been able to work out. It
executes
>> some code that has a 'not implemented' comment:****
>>
>> ** **
>>
>> The code is in WebPage:****
>>
>> ** **
>>
>>             /******
>>
>>              * Validate that each component which wanted to
contribute to
>> the header section actually was****
>>
>>              * able to do so.****
>>
>>              */****
>>
>>             private void validateHeaders()****
>>
>>             {****
>>
>>                         // search for HtmlHeaderContainer in the
first
>> level of children or deeper****
>>
>>                         // if there are transparent resolvers
used****
>>
>>                         HtmlHeaderContainer header =
visitChildren(new
>> IVisitor<Component, HtmlHeaderContainer>()****
>>
>>                         {****
>>
>>                                     public void component(final
Component
>> component, final IVisit<HtmlHeaderContainer> visit)****
>>
>>                                     {****
>>
>>                                                 if (component
instanceof
>> HtmlHeaderContainer)****
>>
>>                                                 {****
>>
>>
visit.stop((
>> HtmlHeaderContainer)component);****
>>
>>                                                 }****
>>
>>                                                 else if (component
>> instanceof TransparentWebMarkupContainer == false)****
>>
>>                                                 {****
>>
>>
>> visit.dontGoDeeper();****
>>
>>                                                 }****
>>
>>                                     }****
>>
>>                         });****
>>
>> ** **
>>
>>                         if (header == null)****
>>
>>                         {****
>>
>>                                     // the markup must at least
contain a
>> <body> tag for wicket to automatically****
>>
>>                                     // create a HtmlHeaderContainer.
Log
>> an error if no header container****
>>
>>                                     // was created but any of the
>> components or behaviors want to contribute****
>>
>>                                     // something to the header.****
>>
>>                                     header = new HtmlHeaderContainer(
>> HtmlHeaderSectionHandler.HEADER_ID);****
>>
>>                                     add(header);****
>>
>> ** **
>>
>>                                     Response orgResponse =
>getRequestCycle
>> ().getResponse();****
>>
>>                                     try****
>>
>>                                     {****
>>
>>                                                 final
>StringResponseresponse = new
>> StringResponse();****
>>
>>                                                 getRequestCycle().
>> setResponse(response);****
>>
>> ** **
>>
>>                                                 // Render all header
>> sections of all components on the page****
>>
>>
>> AbstractHeaderRenderStrategy.get().renderHeader(header,
getPage());****
>>
>>                                                 response.close();****
>>
>> ** **
>>
>>                                                 if
>(response.getBuffer().length()
>> > 0)****
>>
>>                                                 {****
>>
>>                                                             // @TODO
it
>> is not yet working properly. JDo to fix it****
>>
>>
log.error(
>>
>"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^
>^^^^^^^^^^^^^^^");
>> ****
>>
>>
>log.error("You
>> probably forgot to add a <body> or <head> tag to your markup since no
>> Header Container was \n" +****
>>
>>
"
>> found but components were found which want to write to the <head>
>> section.\n" +****
>>
>>
>> response.getBuffer());****
>>
>>
log.error(
>>
>"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^
>^^^^^^^^^^^^^^^");
>> ****
>>
>>                                                 }****
>>
>>                                     }****
>>
>>                                     catch (Exception e)****
>>
>>                                     {****
>>
>>                                                 // just swallow this
>> exception, there isn't much we can do about.****
>>
>>
log.error("header/body
>> check throws exception", e);****
>>
>>                                     }****
>>
>>                                     finally****
>>
>>                                     {****
>>
>>
this.remove(header);****
>>
>>                                                 getRequestCycle().
>> setResponse(orgResponse);****
>>
>>                                     }****
>>
>>                         }****
>>
>>             }****
>>
>> ** **
>>
>> Yours sincerely,****
>>
>> ** **
>>
>> Chris Colman****
>>
>>  ****
>>
>> Pagebloom Team Leader,****
>>
>> Step Ahead Software
>>
>> ****
>>
>> pagebloom - your business & your website growing together****
>>
>> ** **
>>
>> **Sydney**: (+61 2) 9656 1278     ****Canberra****: (+61 2) 6100 2120
>> ****
>>
>> Email: chrisc@stepahead.com.au <//...@stepahead.com.au>****
>>
>> Website:****
>>
>> http://www.pagebloom.com****
>>
>> http://develop.stepaheadsoftware.com****
>>
>>  ****
>>
>> ** **
>>
>
>
>
>--
>Martin Grigorov
>jWeekend
>Training, Consulting, Development
>http://jWeekend.com <http://jweekend.com/>

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


Re: Writing to header causes 'not yet working' code to be executed

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Can you create a quickstart ?
There is a special IMarkupFilter that creates <head> automatically if you
don't have one in your page markup. For some reason it seems it didn't work.

On Sun, Apr 1, 2012 at 11:16 PM, Chris Colman
<ch...@stepaheadsoftware.com>wrote:

> ** **
>
> I’ve overridden renderHead to write to the header of the page but I get a
> strange error message that I have not been able to work out. It executes
> some code that has a ‘not implemented’ comment:****
>
> ** **
>
> The code is in WebPage:****
>
> ** **
>
>             /******
>
>              * Validate that each component which wanted to contribute to
> the header section actually was****
>
>              * able to do so.****
>
>              */****
>
>             private void validateHeaders()****
>
>             {****
>
>                         // search for HtmlHeaderContainer in the first
> level of children or deeper****
>
>                         // if there are transparent resolvers used****
>
>                         HtmlHeaderContainer header = visitChildren(new
> IVisitor<Component, HtmlHeaderContainer>()****
>
>                         {****
>
>                                     public void component(final Component
> component, final IVisit<HtmlHeaderContainer> visit)****
>
>                                     {****
>
>                                                 if (component instanceof
> HtmlHeaderContainer)****
>
>                                                 {****
>
>                                                             visit.stop((
> HtmlHeaderContainer)component);****
>
>                                                 }****
>
>                                                 else if (component
> instanceof TransparentWebMarkupContainer == false)****
>
>                                                 {****
>
>
> visit.dontGoDeeper();****
>
>                                                 }****
>
>                                     }****
>
>                         });****
>
> ** **
>
>                         if (header == null)****
>
>                         {****
>
>                                     // the markup must at least contain a
> <body> tag for wicket to automatically****
>
>                                     // create a HtmlHeaderContainer. Log
> an error if no header container****
>
>                                     // was created but any of the
> components or behaviors want to contribute****
>
>                                     // something to the header.****
>
>                                     header = new HtmlHeaderContainer(
> HtmlHeaderSectionHandler.HEADER_ID);****
>
>                                     add(header);****
>
> ** **
>
>                                     Response orgResponse = getRequestCycle
> ().getResponse();****
>
>                                     try****
>
>                                     {****
>
>                                                 final StringResponseresponse = new
> StringResponse();****
>
>                                                 getRequestCycle().
> setResponse(response);****
>
> ** **
>
>                                                 // Render all header
> sections of all components on the page****
>
>
> AbstractHeaderRenderStrategy.get().renderHeader(header, getPage());****
>
>                                                 response.close();****
>
> ** **
>
>                                                 if (response.getBuffer().length()
> > 0)****
>
>                                                 {****
>
>                                                             // @TODO it
> is not yet working properly. JDo to fix it****
>
>                                                             log.error(
> "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
> ****
>
>                                                             log.error("You
> probably forgot to add a <body> or <head> tag to your markup since no
> Header Container was \n" +****
>
>                                                                         "
> found but components were found which want to write to the <head>
> section.\n" +****
>
>
> response.getBuffer());****
>
>                                                             log.error(
> "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
> ****
>
>                                                 }****
>
>                                     }****
>
>                                     catch (Exception e)****
>
>                                     {****
>
>                                                 // just swallow this
> exception, there isn't much we can do about.****
>
>                                                 log.error("header/body
> check throws exception", e);****
>
>                                     }****
>
>                                     finally****
>
>                                     {****
>
>                                                 this.remove(header);****
>
>                                                 getRequestCycle().
> setResponse(orgResponse);****
>
>                                     }****
>
>                         }****
>
>             }****
>
> ** **
>
> Yours sincerely,****
>
> ** **
>
> Chris Colman****
>
>  ****
>
> Pagebloom Team Leader,****
>
> Step Ahead Software
>
> ****
>
> pagebloom - your business & your website growing together****
>
> ** **
>
> **Sydney**: (+61 2) 9656 1278     ****Canberra****: (+61 2) 6100 2120
> ****
>
> Email: chrisc@stepahead.com.au <//...@stepahead.com.au>****
>
> Website:****
>
> http://www.pagebloom.com****
>
> http://develop.stepaheadsoftware.com****
>
>  ****
>
> ** **
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>