Re: correct way to get css classes of component

2011-01-31 Thread Pedro Santos
You can override the
Component#onComponentTag or AbstractBehavior#onComponentTag  method and use
the ComponentTag API to deal with the tag attributes.

On Mon, Jan 31, 2011 at 9:07 AM, Patrick Petermair 
patrick.peterm...@openforce.com wrote:

 Hi!

 I was trying to solve the problem of replacing a specific css class of a
 wicket component with another css class. Google pointed me to the following
 thread:


 http://apache-wicket.1842946.n4.nabble.com/How-to-add-and-remove-css-classes-the-right-way-td1868408.html

 The nice and simple solution was something like this:

 String oldCss = String.valueOf(this.getMarkupAttributes().get(class));
 String newCss = oldCss.replaceFirst(old, new);
 new SimpleAttributeModifier(class, newCss);

 I've used it and it works just fine.
 Unfortunately - as I've just found out - the method getMarkupAttributes()
 has the following javadoc:

 THIS IS WICKET INTERNAL ONLY. DO NOT USE IT.

 If I'm not supposed to use getMarkupAttributes(), what would be the correct
 way then to get the current css classes of a wicket component?

 Cheers,
 Patrick

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




-- 
Pedro Henrique Oliveira dos Santos


Re: correct way to get css classes of component

2011-01-31 Thread msj121

You can also use an AttributeModifier, which will give you the old value (as
I recall).

overriding the method onComponentTag(ComponentTag tag), will let you easily
put a new variable for your class etc... but you will need to use tag.get(),
and tag.put(tag.get()+...). Looks somewhat messy when you start using
StringBuffers, unless your doing a lot of tag modifications might as well
use AttributeModifier.

In fact use, SimpleAttributeModifier:

component.add(new SimpleAttributeModifier(class, my-css-class));


More methods can be seen here:
https://cwiki.apache.org/WICKET/how-to-modify-an-attribute-on-a-html-tag.html

Matthew
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/correct-way-to-get-css-classes-of-component-tp3248490p3249278.html
Sent from the Users forum mailing list archive at Nabble.com.

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