[Hippo-cms7-user] Head contribution in tag file results in invalid html

Woonsan Ko w.ko at onehippo.com
Fri Sep 10 23:40:52 CEST 2010


  Hi Cuno,

When I test it on Tomcat6, it always print out spaces between start 
element and end element, even in a normal JSP page.
So, I don't think there's a difference between jsp and tag file.
The HeadContributions tag is expanding the element if the element 
contains *text content*.
Because your element definition contains kind of (space) text content 
inside the tag, the HeadContributions tag writes spaces inside the 
output element.
If you don't want to include space text content in the output, you can 
remove any spaces in the tag usages like the following example:

<hst:element var="screen" name="link"><hst:attribute name="type" 
value="text/css" /><hst:attribute name="href" value="${screencss}" 
/><hst:attribute name="rel" value="stylesheet" /><hst:attribute 
name="media" value="screen" /></hst:element>

Regards,

Woonsan


On 09/10/2010 06:55 AM, Cuno wrote:
> Hi,
>
> I want to create a tag file to make adding head contributions a little
> shorter.
>
> This code is in my jsp:
>
> <hst:link var="screencss" path="/css/indivirtual/nl/screen.css" />
> <hst:element var="screen" name="link">
> 	<hst:attribute name="type" value="text/css" />
> 	<hst:attribute name="href" value="${screencss}" />
> 	<hst:attribute name="rel" value="stylesheet" />
> 	<hst:attribute name="media" value="screen" />
> </hst:element>
> <hst:headContribution element="${screen}" />
>
> That works fine, it gives me:<link rel="stylesheet" type="text/css"
> media="screen" href="/site/css/indivirtual/nl/screen.css"/>
>
>
> But when I put the exact same code inside a tag file (linkheadcontrib.tag):
>
> <%@ tag description="A shorter way to define header contributions." %>
> <%@ tag body-content="empty" %>
> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
> <%@ taglib uri="http://www.hippoecm.org/jsp/hst/core" prefix='hst' %>
> <%@ attribute name="path" required="true" %>
>
> <hst:link var="screencss" path="/css/indivirtual/nl/screen.css" />
> <hst:element var="screen" name="link">
> 	<hst:attribute name="type" value="text/css" />
> 	<hst:attribute name="href" value="${screencss}" />
> 	<hst:attribute name="rel" value="stylesheet" />
> 	<hst:attribute name="media" value="screen" />
> </hst:element>
> <hst:headContribution element="${screen}" />
>
> Then I get a different result:
>
> <link rel="stylesheet" type="text/css" media="screen"
> href="/site/css/indivirtual/nl/screen.css">
> 			
> 			
> 			
> 			
> </link>
>
> which isn't valid xhtml according to the w3.org validator.
>
>
> Does anyone know why this is happening and/or how to fix this in the tag
> file?
>
> Regards,
> Cuno


-- 
w.ko at onehippo.com     www.onehippo.com
NORTH AMERICA • SAN FRANCISCO - Hippo USA Inc. 185 H Street, Suite B Petaluma CA 94952 +1 (707) 773-4646
EUROPE • AMSTERDAM - Hippo B.V. Oosteinde 11 1017 WT Amsterdam +31(0)20-5224466




More information about the Hippo-cms7-user mailing list