You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jianfei Liao <ji...@gmail.com> on 2009/08/08 07:40:09 UTC

how to use the BodyTagAttributeModifier class?

i'm trying to dynamically add the class attribute to the body tag, and i
came across this class. but i can't seem to understand how to use this
class. i have something like this in my page class (or panel class, as i
tried with that too):

add(new BodyTagAttributeModifier("class", "homepage", this));

this doesn't even compile, saying there's something wrong with the 2nd
parameter. but i think String is automatically considered a Model in wicket,
like the Label class. am i missing something here? i tried to search up on
this topic, but there is no concrete example on how to use this class. i'm
using wicket 1.4

Re: how to use the BodyTagAttributeModifier class?

Posted by jianfei <ji...@gmail.com>.
So you mean i need to create a panel just for the purpose of changing the
body tag attribute? that sounds a little bit odd.

as for the other way of using the AttributeModifier, it works ok but then
now you have to expose the body component thru a getter method as other
components has to get access to it when they are added to the page, since
body contains all the other stuff. that seems even more hassle. or unless
i'm mistaking something here?


Andreas Petersson wrote:
> 
> as i understand it from the javadoc you only need a 
> BodyTagAttributeModifier if you create a PANEL that has the desire to 
> add something to the parent <body> tag.
> since you do not have a panel, but rather an ordinary page, you can 
> simply assign a wicket:id to your body and alter the attribute as you 
> whish, either as described by you or by using the more common 
> AttributeModifier
> 
> in html: <body wicket:id="mybody">...
> 
> in code: new WebMarkupContainer("mybody").add(new 
> AttributeModifier("class", true, new Model<String>("myclass")));
> string could only be "automatically" cast to model because it does not 
> implement the IModel interface.String is not aware that IModel even 
> exists, like all other core java classes.
> 
>> ok, so i did 
>> i would appreciate if someone can explain to me why the above code
>> actually
>> works and the BodyTagAttributeModifier didn't. btw, i now knew that
>> String
>> is not automatically cast to Model. my bad.
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-use-the-BodyTagAttributeModifier-class--tp24875297p24881924.html
Sent from the Wicket - User 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 use the BodyTagAttributeModifier class?

Posted by Andreas Petersson <an...@petersson.at>.
as i understand it from the javadoc you only need a 
BodyTagAttributeModifier if you create a PANEL that has the desire to 
add something to the parent <body> tag.
since you do not have a panel, but rather an ordinary page, you can 
simply assign a wicket:id to your body and alter the attribute as you 
whish, either as described by you or by using the more common 
AttributeModifier

in html: <body wicket:id="mybody">...

in code: new WebMarkupContainer("mybody").add(new 
AttributeModifier("class", true, new Model<String>("myclass")));
string could only be "automatically" cast to model because it does not 
implement the IModel interface.String is not aware that IModel even 
exists, like all other core java classes.

> ok, so i did 
> i would appreciate if someone can explain to me why the above code actually
> works and the BodyTagAttributeModifier didn't. btw, i now knew that String
> is not automatically cast to Model. my bad.




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


Re: how to use the BodyTagAttributeModifier class?

Posted by jianfei <ji...@gmail.com>.
ok, so i did research again for a while, and i think i got the result i want
by using the aother method described here:
http://www.nabble.com/Dynamically-Change-css-style-of-body-tag-td13505908.html#a13505908

so basically here is the code to get add a class attribute to the body tag:

        <body wicket:id="body"> <!-- not wicket:id="foo" like in the link
-->

        add(new WebMarkupContainer("body"){
            @Override
            public boolean isTransparentResolver() {
                return true;
            }
            @Override
            protected void onComponentTag(ComponentTag tag) {
                tag.put("class",  "somestyle");
            }
        });

i would appreciate if someone can explain to me why the above code actually
works and the BodyTagAttributeModifier didn't. btw, i now knew that String
is not automatically cast to Model. my bad.
anyways, what's wrong with this:

        add(new BodyTagAttributeModifier("class", true, new
Model<String>("somestyle"), this));

it looks much cleaner than using the WebMarkupContainer. i would really like
to get it working.


jianfei wrote:
> 
> i'm trying to dynamically add the class attribute to the body tag, and i
> came across this class. but i can't seem to understand how to use this
> class. i have something like this in my page class (or panel class, as i
> tried with that too):
> 
> add(new BodyTagAttributeModifier("class", "homepage", this));
> 
> this doesn't even compile, saying there's something wrong with the 2nd
> parameter. but i think String is automatically considered a Model in
> wicket,
> like the Label class. am i missing something here? i tried to search up on
> this topic, but there is no concrete example on how to use this class. i'm
> using wicket 1.4
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-use-the-BodyTagAttributeModifier-class--tp24875297p24875789.html
Sent from the Wicket - User 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