How to modify attribute (eg. class) in component with setRenderBodyOnly(true) ?

2012-02-22 Thread Daniel Stoch
Hi,

Is it possible to modify tag attribute (eg. add a CSS class) of
component which has set renderBodyOnly flag to true?
When using component.add(new AttributeModifier(...)) it has no effect,
because a tag in which this class attribute is appended is not
rendered in HTML (because of setRenderBodyOnly(true)).

Here is an example:
LinkContainer is a component (extends Panel) which has setRenderBodyOnly(true).

wicket:panel
a wicket:id=linkwicket:container wicket:id=linkContent[link
content]/wicket:container/a
/wicket:panel

Somewhere inside a page or panel:
add(new LinkContainer(link, ...).add(new AttributeModifier(class,
Model.of(my-link-style;
But of course this  class='my-link-style'  will not be rendered anywhere.

I want to add a class attribute to contained a tag but using a
behavior which can be added to the whole LinkContainer. Is it any
simple solution to achieve this?

--
DS

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



Re: How to modify attribute (eg. class) in component with setRenderBodyOnly(true) ?

2012-02-22 Thread Martin Grigorov
Hi,

So you want to not have a (because this is what
.setRenderBodyOnly(true) does) and in the same time you want to set a
class an that non-existing tag ?!

The easiest way is to remove the call to .setRenderBodyOnly(true).

On Wed, Feb 22, 2012 at 11:38 AM, Daniel Stoch daniel.st...@gmail.com wrote:
 Hi,

 Is it possible to modify tag attribute (eg. add a CSS class) of
 component which has set renderBodyOnly flag to true?
 When using component.add(new AttributeModifier(...)) it has no effect,
 because a tag in which this class attribute is appended is not
 rendered in HTML (because of setRenderBodyOnly(true)).

 Here is an example:
 LinkContainer is a component (extends Panel) which has 
 setRenderBodyOnly(true).

 wicket:panel
        a wicket:id=linkwicket:container wicket:id=linkContent[link
 content]/wicket:container/a
 /wicket:panel

 Somewhere inside a page or panel:
 add(new LinkContainer(link, ...).add(new AttributeModifier(class,
 Model.of(my-link-style;
 But of course this  class='my-link-style'  will not be rendered anywhere.

 I want to add a class attribute to contained a tag but using a
 behavior which can be added to the whole LinkContainer. Is it any
 simple solution to achieve this?

 --
 DS

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




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

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



Re: How to modify attribute (eg. class) in component with setRenderBodyOnly(true) ?

2012-02-22 Thread Daniel Stoch
No. I want to have a. When you use this LinkContainer from my
example in HTML like:
div wicket:id=link
/div

It will be rendered as:

a wicket:id=link.../a

So any attributes modified using behavior will disappear.


But if LinkContainer will not have setRenderBodyOnly(true), the the
corresponding HTML will be:

div wicket:id=link class='my-link-style'
  a wicket:id=link.../a
/div


--
DS

On Wed, Feb 22, 2012 at 11:49 AM, Martin Grigorov mgrigo...@apache.org wrote:
 Hi,

 So you want to not have a (because this is what
 .setRenderBodyOnly(true) does) and in the same time you want to set a
 class an that non-existing tag ?!

 The easiest way is to remove the call to .setRenderBodyOnly(true).

 On Wed, Feb 22, 2012 at 11:38 AM, Daniel Stoch daniel.st...@gmail.com wrote:
 Hi,

 Is it possible to modify tag attribute (eg. add a CSS class) of
 component which has set renderBodyOnly flag to true?
 When using component.add(new AttributeModifier(...)) it has no effect,
 because a tag in which this class attribute is appended is not
 rendered in HTML (because of setRenderBodyOnly(true)).

 Here is an example:
 LinkContainer is a component (extends Panel) which has 
 setRenderBodyOnly(true).

 wicket:panel
        a wicket:id=linkwicket:container wicket:id=linkContent[link
 content]/wicket:container/a
 /wicket:panel

 Somewhere inside a page or panel:
 add(new LinkContainer(link, ...).add(new AttributeModifier(class,
 Model.of(my-link-style;
 But of course this  class='my-link-style'  will not be rendered anywhere.

 I want to add a class attribute to contained a tag but using a
 behavior which can be added to the whole LinkContainer. Is it any
 simple solution to achieve this?

 --
 DS

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




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

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


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



Re: How to modify attribute (eg. class) in component with setRenderBodyOnly(true) ?

2012-02-22 Thread Martin Grigorov
On Wed, Feb 22, 2012 at 12:01 PM, Daniel Stoch daniel.st...@gmail.com wrote:
 No. I want to have a. When you use this LinkContainer from my
 example in HTML like:
 div wicket:id=link
 /div

 It will be rendered as:

 a wicket:id=link.../a

 So any attributes modified using behavior will disappear.


 But if LinkContainer will not have setRenderBodyOnly(true), the the
 corresponding HTML will be:

 div wicket:id=link class='my-link-style'
  a wicket:id=link.../a
 /div

Now it is more clear what you do.
You need to add the AttributeModifier to the Link, not to the
LinkContainer if you want to manipulate a.



 --
 DS

 On Wed, Feb 22, 2012 at 11:49 AM, Martin Grigorov mgrigo...@apache.org 
 wrote:
 Hi,

 So you want to not have a (because this is what
 .setRenderBodyOnly(true) does) and in the same time you want to set a
 class an that non-existing tag ?!

 The easiest way is to remove the call to .setRenderBodyOnly(true).

 On Wed, Feb 22, 2012 at 11:38 AM, Daniel Stoch daniel.st...@gmail.com 
 wrote:
 Hi,

 Is it possible to modify tag attribute (eg. add a CSS class) of
 component which has set renderBodyOnly flag to true?
 When using component.add(new AttributeModifier(...)) it has no effect,
 because a tag in which this class attribute is appended is not
 rendered in HTML (because of setRenderBodyOnly(true)).

 Here is an example:
 LinkContainer is a component (extends Panel) which has 
 setRenderBodyOnly(true).

 wicket:panel
        a wicket:id=linkwicket:container wicket:id=linkContent[link
 content]/wicket:container/a
 /wicket:panel

 Somewhere inside a page or panel:
 add(new LinkContainer(link, ...).add(new AttributeModifier(class,
 Model.of(my-link-style;
 But of course this  class='my-link-style'  will not be rendered anywhere.

 I want to add a class attribute to contained a tag but using a
 behavior which can be added to the whole LinkContainer. Is it any
 simple solution to achieve this?

 --
 DS

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




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

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


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




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

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



Re: How to modify attribute (eg. class) in component with setRenderBodyOnly(true) ?

2012-02-22 Thread Daniel Stoch
On Wed, Feb 22, 2012 at 12:11 PM, Martin Grigorov mgrigo...@apache.org wrote:
 On Wed, Feb 22, 2012 at 12:01 PM, Daniel Stoch daniel.st...@gmail.com wrote:
 No. I want to have a. When you use this LinkContainer from my
 example in HTML like:
 div wicket:id=link
 /div

 It will be rendered as:

 a wicket:id=link.../a

 So any attributes modified using behavior will disappear.


 But if LinkContainer will not have setRenderBodyOnly(true), the the
 corresponding HTML will be:

 div wicket:id=link class='my-link-style'
  a wicket:id=link.../a
 /div

 Now it is more clear what you do.
 You need to add the AttributeModifier to the Link, not to the
 LinkContainer if you want to manipulate a.


Well, I know it is possible in this way. But my question is more
general: does using behaviors which changes a markup (like
AttributeModifier) on components with setRenderBodyOnly(true) make
sense?

To add the AttributeModifier to the Link I have to write extra method
inside a LinkContainer which adds a behavior to enclosing component
(Link is created inside LinkContainer and because of ecapsulation it
should not be visible outside it). But the cleaner solution will be to
add a behavior to LinkContainer, but then it should be transparently
added to the one of its child components.
Then I can use AttributeModifier (or related behaviors) the same way
with component which has setRenderBodyOnly(true) or not. But now I
need to know a component implementation to decide if I can use such
modifiers with it or no.

--
DS

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



Re: How to modify attribute (eg. class) in component with setRenderBodyOnly(true) ?

2012-02-22 Thread Daniel Stoch
On Wed, Feb 22, 2012 at 12:31 PM, Martin Grigorov mgrigo...@apache.org wrote:
 On Wed, Feb 22, 2012 at 12:20 PM, Daniel Stoch daniel.st...@gmail.com wrote:
 On Wed, Feb 22, 2012 at 12:11 PM, Martin Grigorov mgrigo...@apache.org 
 wrote:
 On Wed, Feb 22, 2012 at 12:01 PM, Daniel Stoch daniel.st...@gmail.com 
 wrote:
 No. I want to have a. When you use this LinkContainer from my
 example in HTML like:
 div wicket:id=link
 /div

 It will be rendered as:

 a wicket:id=link.../a

 So any attributes modified using behavior will disappear.


 But if LinkContainer will not have setRenderBodyOnly(true), the the
 corresponding HTML will be:

 div wicket:id=link class='my-link-style'
  a wicket:id=link.../a
 /div

 Now it is more clear what you do.
 You need to add the AttributeModifier to the Link, not to the
 LinkContainer if you want to manipulate a.


 Well, I know it is possible in this way. But my question is more
 general: does using behaviors which changes a markup (like
 AttributeModifier) on components with setRenderBodyOnly(true) make
 sense?

 No.


 To add the AttributeModifier to the Link I have to write extra method
 inside a LinkContainer which adds a behavior to enclosing component
 (Link is created inside LinkContainer and because of ecapsulation it
 should not be visible outside it). But the cleaner solution will be to
 add a behavior to LinkContainer, but then it should be transparently
 added to the one of its child components.

 To which child exactly ? How to decide that for you ?

 Then I can use AttributeModifier (or related behaviors) the same way
 with component which has setRenderBodyOnly(true) or not. But now I
 need to know a component implementation to decide if I can use such
 modifiers with it or no.

 Each behavior has a reference to the component it is bound to. So you
 can assign your own Behavior to the parent class and then in
 behavior's onComponentTag, renderHead(), ... you can do whatever you
 need with the parent and all its children. It is a bit harder to get
 the children ComponentTags but it is possible: new
 MarkupStream(getMarkup()) and iterate over the elements in the
 MarkupStream.


Thanks for your feedback and suggestions.

I have done a simple behavior to achieve what I want. Maybe this is
not very elegant solution but it should work. It writes out attributes
added as AttributeModifiers to a parent component to a child component
which has this behavior.

public class AttributeModifierPropagator extends AbstractBehavior {

  private final MarkupContainer parent;

  public AttributeModifierPropagator(MarkupContainer parent) {
super();
if (parent == null) {
  throw new IllegalArgumentException(Argument [parent] cannot be null);
}
this.parent = parent;
  }

  @Override
  public void onComponentTag(Component component, ComponentTag tag) {
for (IBehavior behavior : parent.getBehaviors()) {
  if ((behavior instanceof AttributeModifier) || (behavior
instanceof SimpleAttributeModifier)) {
behavior.onComponentTag(component, tag);
  }
}
  }

}

And then inside a LinkContainer after creating nested Link link I can
add this behavior to it:
link.add(new AttributeModifierPropagator(this));

--
DS

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