You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Edvin Syse <ed...@sysedata.no> on 2007/11/23 14:17:28 UTC

How do I get a hold of the element so I can add class/id etc?

Hi,

I have a page that extends another page, and concequently the "parent" 
page template contains the <body> element that is beeing rendered. The 
"subpage" template contains:

<body>
	<wicket:extend>
		content...
	</wicket:extend>
</body>

In some pages I would like to add either an id or class to the body 
element. How I can get a hold of the body to do this from the Page-class?

Sorry for the bad explanation :)

Sincerely,
Edvin Syse
Syse Data AS


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


Re: How do I get a hold of the element so I can add class/id etc?

Posted by Al Maw <al...@gmail.com>.
Edvin Syse wrote:
> Johan Compagner skrev:
>> BodyOnLoadContainer is dropped because you shouldn't try to generate 
>> <body
>> onload=xxx>
>>
>> What you should do is have a header contributor and add call
>>
>> IHeaderResponse.renderOnLoadJavascript(String javascript);
> 
> OK. Maybe one of you guys could remove the reference from the javadoc as 
> well? (Line 412 of MarkupContainer.java as of 1.3 rc1).

Done. Thanks for spotting it.

Regards,

Al

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


Re: How do I get a hold of the element so I can add class/id etc?

Posted by Edvin Syse <ed...@sysedata.no>.
Johan Compagner skrev:
> BodyOnLoadContainer is dropped because you shouldn't try to generate <body
> onload=xxx>
> 
> What you should do is have a header contributor and add call
> 
> IHeaderResponse.renderOnLoadJavascript(String javascript);

OK. Maybe one of you guys could remove the reference from the javadoc as well? (Line 412 of MarkupContainer.java as of 1.3 rc1).

-- Edvin

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


Re: How do I get a hold of the element so I can add class/id etc?

Posted by Johan Compagner <jc...@gmail.com>.
BodyOnLoadContainer is dropped because you shouldn't try to generate <body
onload=xxx>

What you should do is have a header contributor and add call

IHeaderResponse.renderOnLoadJavascript(String javascript);

johan




On Nov 23, 2007 10:09 PM, Edvin Syse <ed...@sysedata.no> wrote:

> Al Maw wrote:
> >> I really want to avoid this, as it seems messy having to add all
> >> components to the body markupcontainer. I can't believe this is the
> >> Wicket way to solve this problem :)
> >
> > See MarkupContainer#isTransparentResolver().
>
> Sweet! Thank you, that made by day :) It seems Wicket has smooth solutions
> to almost any problem :)
>
> By the way, it seems that the javadoc references a component that doesn't
> exist (BodyOnLoadContainer):
>
> * Some MarkupContainers (e.g. HtmlHeaderContainer, BodyOnLoadContainer)
> have to be transparent
> * with respect to there child components. A transparent container gets its
> children from its
> * parent container.
>
> -- Edvin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How do I get a hold of the element so I can add class/id etc?

Posted by Edvin Syse <ed...@sysedata.no>.
Al Maw wrote:
>> I really want to avoid this, as it seems messy having to add all 
>> components to the body markupcontainer. I can't believe this is the 
>> Wicket way to solve this problem :)
> 
> See MarkupContainer#isTransparentResolver().

Sweet! Thank you, that made by day :) It seems Wicket has smooth solutions to almost any problem :)

By the way, it seems that the javadoc references a component that doesn't exist (BodyOnLoadContainer):

* Some MarkupContainers (e.g. HtmlHeaderContainer, BodyOnLoadContainer) have to be transparent
* with respect to there child components. A transparent container gets its children from its
* parent container.

-- Edvin

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


Re: How do I get a hold of the element so I can add class/id etc?

Posted by Al Maw <al...@gmail.com>.
Edvin Syse wrote:
>> The <body> tag from your subpage is discarded. The <body> tag that is
>> rendered comes from some parent page. One way to do this would be to
>> attach a WebMarkupContainer to the <body> tag in the parent page and
>> expose it via a getter:
> 
> 
> I really want to avoid this, as it seems messy having to add all 
> components to the body markupcontainer. I can't believe this is the 
> Wicket way to solve this problem :)

See MarkupContainer#isTransparentResolver().


Regards,

Al

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


Re: How do I get a hold of the element so I can add class/id etc?

Posted by Edvin Syse <ed...@sysedata.no>.
> How about org.apache.wicket.markup.html.body.BodyTagAttributeModifier?
>
> hth,
>   Gerolf
>   
Already tried it, the name sounds right, but it seems to be a helper for 
Panels in some way, I don't fully understand the javadoc:


          "org.apache.wicket.markup.html.body.BodyTagAttributeModifier

An attribute modifier specifically for body tags.

Panels have associated markup files and if they contain |<wicket:head>| 
and |<body onLoad="...">| then the body's |onLoad| attribute will be 
appended to the page's onLoad attribute. That accretion happens by means 
of an AttributeModifier which the Panel adds to the body container. In 
the case where the Panel is removed or replaced, then the 
AttributeModifier must be removed or at least disabled. That exactly is 
what this special purpose AttributeModifier does, i.e. it disables 
itself if the owner component (Panel) is removed or replaced."

Doesn't seem to be the right one..

-- Edvin

> On Nov 23, 2007 7:05 PM, Edvin Syse <ed...@sysedata.no> wrote:
>
>   
>> John Krasnay skrev:
>>     
>>> On Fri, Nov 23, 2007 at 05:05:51PM +0100, Edvin Syse wrote:
>>>
>>>       
>>>> John Krasnay wrote:
>>>>
>>>>         
>>>>> Perhaps there's another way to solve your problem. Why are you
>>>>>           
>> modifying
>>     
>>>>> the class of <body>? To change it's styling? Why not instead split
>>>>>           
>> your
>>     
>>>>> styles into different stylesheets and conditionally include the right
>>>>> one using a header contribution from the child page?
>>>>>
>>>>>
>>>>>           
>>>> I'm developing a virtualhosted CMS-system, so in this case that won't
>>>>         
>> be
>>     
>>>> possible or at least not intuitive to the user. The user can edit the
>>>> head section for each page, and also a global head section that are
>>>>         
>> both
>>     
>>>> contributed. Some users want's to lay out components differently
>>>> depending on the page and setting a class on the body gives them an
>>>>         
>> easy
>>     
>>>> way of controlling that.
>>>>
>>>>
>>>>         
>>> Well, now you're outside my Wicket comfort zone :-(
>>>
>>>       
>> Arghfl.. the PHP-guys at work is gonna have a feast with me not beeing
>> able to change the <body> element.. hehe :)
>>
>> But maybe it is possible to hook into the onComponentTag method for the
>> <body> element when it is rendered? I guess it is treated specially
>> somewhere deep inside the Wicket internals, but I can't locate it. Can
>> anyone help?
>>
>> -- Edvin
>>
>>     
>
>   

Re: How do I get a hold of the element so I can add class/id etc?

Posted by Gerolf Seitz <ge...@gmail.com>.
How about org.apache.wicket.markup.html.body.BodyTagAttributeModifier?

hth,
  Gerolf

On Nov 23, 2007 7:05 PM, Edvin Syse <ed...@sysedata.no> wrote:

> John Krasnay skrev:
> > On Fri, Nov 23, 2007 at 05:05:51PM +0100, Edvin Syse wrote:
> >
> >> John Krasnay wrote:
> >>
> >>> Perhaps there's another way to solve your problem. Why are you
> modifying
> >>> the class of <body>? To change it's styling? Why not instead split
> your
> >>> styles into different stylesheets and conditionally include the right
> >>> one using a header contribution from the child page?
> >>>
> >>>
> >> I'm developing a virtualhosted CMS-system, so in this case that won't
> be
> >> possible or at least not intuitive to the user. The user can edit the
> >> head section for each page, and also a global head section that are
> both
> >> contributed. Some users want's to lay out components differently
> >> depending on the page and setting a class on the body gives them an
> easy
> >> way of controlling that.
> >>
> >>
> >
> > Well, now you're outside my Wicket comfort zone :-(
> >
> Arghfl.. the PHP-guys at work is gonna have a feast with me not beeing
> able to change the <body> element.. hehe :)
>
> But maybe it is possible to hook into the onComponentTag method for the
> <body> element when it is rendered? I guess it is treated specially
> somewhere deep inside the Wicket internals, but I can't locate it. Can
> anyone help?
>
> -- Edvin
>

Re: How do I get a hold of the element so I can add class/id etc?

Posted by Edvin Syse <ed...@sysedata.no>.
John Krasnay skrev:
> On Fri, Nov 23, 2007 at 05:05:51PM +0100, Edvin Syse wrote:
>   
>> John Krasnay wrote:
>>     
>>> Perhaps there's another way to solve your problem. Why are you modifying
>>> the class of <body>? To change it's styling? Why not instead split your
>>> styles into different stylesheets and conditionally include the right
>>> one using a header contribution from the child page?
>>>  
>>>       
>> I'm developing a virtualhosted CMS-system, so in this case that won't be 
>> possible or at least not intuitive to the user. The user can edit the 
>> head section for each page, and also a global head section that are both 
>> contributed. Some users want's to lay out components differently 
>> depending on the page and setting a class on the body gives them an easy 
>> way of controlling that.
>>
>>     
>
> Well, now you're outside my Wicket comfort zone :-(
>   
Arghfl.. the PHP-guys at work is gonna have a feast with me not beeing 
able to change the <body> element.. hehe :)

But maybe it is possible to hook into the onComponentTag method for the 
<body> element when it is rendered? I guess it is treated specially 
somewhere deep inside the Wicket internals, but I can't locate it. Can 
anyone help?

-- Edvin

Re: How do I get a hold of the element so I can add class/id etc?

Posted by John Krasnay <jo...@krasnay.ca>.
On Fri, Nov 23, 2007 at 05:05:51PM +0100, Edvin Syse wrote:
> John Krasnay wrote:
> >
> >Perhaps there's another way to solve your problem. Why are you modifying
> >the class of <body>? To change it's styling? Why not instead split your
> >styles into different stylesheets and conditionally include the right
> >one using a header contribution from the child page?
> >  
> I'm developing a virtualhosted CMS-system, so in this case that won't be 
> possible or at least not intuitive to the user. The user can edit the 
> head section for each page, and also a global head section that are both 
> contributed. Some users want's to lay out components differently 
> depending on the page and setting a class on the body gives them an easy 
> way of controlling that.
> 

Well, now you're outside my Wicket comfort zone :-(

jk

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


Re: How do I get a hold of the element so I can add class/id etc?

Posted by Edvin Syse <ed...@sysedata.no>.
John Krasnay wrote:
> On Fri, Nov 23, 2007 at 04:24:21PM +0100, Edvin Syse wrote:
>   
>>> The <body> tag from your subpage is discarded. The <body> tag that is
>>> rendered comes from some parent page. One way to do this would be to
>>> attach a WebMarkupContainer to the <body> tag in the parent page and
>>> expose it via a getter:
>>>       
>> I really want to avoid this, as it seems messy having to add all 
>> components to the body markupcontainer. I can't believe this is the 
>> Wicket way to solve this problem :)
>>
>>     
>
> Perhaps there's another way to solve your problem. Why are you modifying
> the class of <body>? To change it's styling? Why not instead split your
> styles into different stylesheets and conditionally include the right
> one using a header contribution from the child page?
>   
I'm developing a virtualhosted CMS-system, so in this case that won't be 
possible or at least not intuitive to the user. The user can edit the 
head section for each page, and also a global head section that are both 
contributed. Some users want's to lay out components differently 
depending on the page and setting a class on the body gives them an easy 
way of controlling that.

-- Edvin

Re: How do I get a hold of the element so I can add class/id etc?

Posted by John Krasnay <jo...@krasnay.ca>.
On Fri, Nov 23, 2007 at 04:24:21PM +0100, Edvin Syse wrote:
> >The <body> tag from your subpage is discarded. The <body> tag that is
> >rendered comes from some parent page. One way to do this would be to
> >attach a WebMarkupContainer to the <body> tag in the parent page and
> >expose it via a getter:
> 
> 
> I really want to avoid this, as it seems messy having to add all 
> components to the body markupcontainer. I can't believe this is the 
> Wicket way to solve this problem :)
> 

Perhaps there's another way to solve your problem. Why are you modifying
the class of <body>? To change it's styling? Why not instead split your
styles into different stylesheets and conditionally include the right
one using a header contribution from the child page?

jk

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


Re: How do I get a hold of the element so I can add class/id etc?

Posted by Edvin Syse <ed...@sysedata.no>.
> The <body> tag from your subpage is discarded. The <body> tag that is
> rendered comes from some parent page. One way to do this would be to
> attach a WebMarkupContainer to the <body> tag in the parent page and
> expose it via a getter:


I really want to avoid this, as it seems messy having to add all 
components to the body markupcontainer. I can't believe this is the 
Wicket way to solve this problem :)

-- Edvin

> public class ParentPage extends WebPage {
> 
>   private WebMarkupContainer body;
> 
>   public ParentPage() {
>     body = new WebMarkupContainer("body");
>     // need to add all children to the body tag
>     // instead of the page
>   }
> 
>   protected WebMarkupContainter getBody() {
>     return body;
>   }
> }
> 
> public class ChildPage extends ParentPage {
>   public ChildPage() {
>     getBody().add(new SimpleAttributeModifier("class", "foo"));
>   }
> }
> 
> jk
> 
> ---------------------------------------------------------------------
> 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 do I get a hold of the element so I can add class/id etc?

Posted by John Krasnay <jo...@krasnay.ca>.
On Fri, Nov 23, 2007 at 02:17:28PM +0100, Edvin Syse wrote:
> Hi,
> 
> I have a page that extends another page, and concequently the "parent" 
> page template contains the <body> element that is beeing rendered. The 
> "subpage" template contains:
> 
> <body>
> 	<wicket:extend>
> 		content...
> 	</wicket:extend>
> </body>
> 
> In some pages I would like to add either an id or class to the body 
> element. How I can get a hold of the body to do this from the Page-class?
> 

Hi Edvin,

The <body> tag from your subpage is discarded. The <body> tag that is
rendered comes from some parent page. One way to do this would be to
attach a WebMarkupContainer to the <body> tag in the parent page and
expose it via a getter:

public class ParentPage extends WebPage {

  private WebMarkupContainer body;

  public ParentPage() {
    body = new WebMarkupContainer("body");
    // need to add all children to the body tag
    // instead of the page
  }

  protected WebMarkupContainter getBody() {
    return body;
  }
}

public class ChildPage extends ParentPage {
  public ChildPage() {
    getBody().add(new SimpleAttributeModifier("class", "foo"));
  }
}

jk

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