You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Warren Bell <Wa...@clarksnutrition.com> on 2010/04/15 19:44:49 UTC
Adding attributes to child components in a behavior.
Is there a way to add attributes to child components in a behavior that
is added to a page? I want to create a behavior that is added to a page
that adds some js to the header and then adds some js in an onfocus
attribute of each child form component on the page. I have the list of
child form components, but can't figure out how to add the attribute to
the components.
Warren
Re: Adding attributes to child components in a behavior.
Posted by Cemal Bayramoglu <jW...@cabouge.com>.
... and if you're not building your component tree before you add such
an IBehaviour to the parent container you can instead override
onBeforeRender on that container to do something like:
@Override
public void onBeforeRender() {
super.onBeforeRender();
visitChildren(new IVisitor<Component>(){
@Override
public Object component(Component component) {
component.add(new SimpleAttributeModifier("class","goodChild"));
return IVisitor.CONTINUE_TRAVERSAL;
}
});
}
Regards - Cemal
jWeekend
OO & Java Technologies, Wicket
Consulting, Development, Training
http://jWeekend.com
On 15 April 2010 21:17, Cemal Bayramoglu <jW...@cabouge.com> wrote:
> I assume you were trying this in beforeRender of your behaviour, which
> as you say is too late.
> If you really need to use a behaviour encapsulate all this, try
> something like the following, but some may feel its a little
> politically incorrect to do this in bind.
> class MyBehaviour extends AbstractBehavior{
> @Override
> public void bind(Component component) {
> if(!(component instanceof MarkupContainer)){
> throw new RuntimeException("contaıners only please");
> }
> visitChildren(new IVisitor<Component>(){
> @Override
> public Object component(Component component) {
> component.add(new SimpleAttributeModifier("class","goodChild"));
> return IVisitor.CONTINUE_TRAVERSAL;
> }
> });
> }
> }
>
> Regards - Cemal
> jWeekend
> OO & Java Technologies, Wicket
> Consulting, Development, Training
> http://jWeekend.com
>
>
> On 15 April 2010 20:17, Warren Bell <wa...@gmail.com> wrote:
>> I have that figured out, I just don't know how to add the attribute to each
>> component. I can't add a behavior, since "Cannot modify component hierarchy
>> after render phase has started (page version cant change then anymore)" Can
>> I even do this in a behavior?
>>
>> Cemal Bayramoglu wrote:
>>>
>>> Warren,
>>>
>>> See MarkupContainer#visitChildren
>>>
>>> Regards - Cemal
>>> jWeekend
>>> OO & Java Technologies, Wicket
>>> Consulting, Development, Training
>>> http://jWeekend.com
>>>
>>> On 15 April 2010 18:44, Warren Bell <Wa...@clarksnutrition.com> wrote:
>>>
>>>>
>>>> Is there a way to add attributes to child components in a behavior that
>>>> is added to a page? I want to create a behavior that is added to a page
>>>> that adds some js to the header and then adds some js in an onfocus
>>>> attribute of each child form component on the page. I have the list of
>>>> child form components, but can't figure out how to add the attribute to
>>>> the components.
>>>>
>>>> Warren
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>> --
>> Thanks,
>>
>> Warren Bell
>>
>>
>> ---------------------------------------------------------------------
>> 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: Adding attributes to child components in a behavior.
Posted by Cemal Bayramoglu <jW...@cabouge.com>.
I assume you were trying this in beforeRender of your behaviour, which
as you say is too late.
If you really need to use a behaviour encapsulate all this, try
something like the following, but some may feel its a little
politically incorrect to do this in bind.
class MyBehaviour extends AbstractBehavior{
@Override
public void bind(Component component) {
if(!(component instanceof MarkupContainer)){
throw new RuntimeException("contaıners only please");
}
visitChildren(new IVisitor<Component>(){
@Override
public Object component(Component component) {
component.add(new SimpleAttributeModifier("class","goodChild"));
return IVisitor.CONTINUE_TRAVERSAL;
}
});
}
}
Regards - Cemal
jWeekend
OO & Java Technologies, Wicket
Consulting, Development, Training
http://jWeekend.com
On 15 April 2010 20:17, Warren Bell <wa...@gmail.com> wrote:
> I have that figured out, I just don't know how to add the attribute to each
> component. I can't add a behavior, since "Cannot modify component hierarchy
> after render phase has started (page version cant change then anymore)" Can
> I even do this in a behavior?
>
> Cemal Bayramoglu wrote:
>>
>> Warren,
>>
>> See MarkupContainer#visitChildren
>>
>> Regards - Cemal
>> jWeekend
>> OO & Java Technologies, Wicket
>> Consulting, Development, Training
>> http://jWeekend.com
>>
>> On 15 April 2010 18:44, Warren Bell <Wa...@clarksnutrition.com> wrote:
>>
>>>
>>> Is there a way to add attributes to child components in a behavior that
>>> is added to a page? I want to create a behavior that is added to a page
>>> that adds some js to the header and then adds some js in an onfocus
>>> attribute of each child form component on the page. I have the list of
>>> child form components, but can't figure out how to add the attribute to
>>> the components.
>>>
>>> Warren
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> Thanks,
>
> Warren Bell
>
>
> ---------------------------------------------------------------------
> 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: Adding attributes to child components in a behavior.
Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
Hi Warren,
The way I normally handle this situation is to create a javascript
emitting behaviour that is attached to the container. This behaviour
will emit the necessary javascript method to do what you need to do.
Then for each child component you can use an AttributeModifier to write
their onclick callback to call the custom method being emitted by the
container attached behavior.
All the logic can be handled in the implementation details of the custom
method/Object that was emitted.
To get the "onclick" actions emitted before the rendering phase either
include it within the container.onBeforeRender() method, to call the
visitChildren method, or perhaps within your behavior override the
AbstractBehavior.beforeRender(Component c) method.
I've written something like this for a table of check boxes where each
column header is a radio button. Selecting column 2's radio button
causes all of the check boxes in column 1 to become disabled and all the
check boxes in column 2 to become enabled. In my case I made the
behaviour aware of the components in each column and then during
rendering the javascript it writes out an array of markup id's for each
table column.
But if you don't have the child components in scope when adding the
behavior to the container adding the child behaviors before rendering
starts should let things work.
Regards,
Mike
> I have that figured out, I just don't know how to add the attribute to
> each component. I can't add a behavior, since "Cannot modify component
> hierarchy after render phase has started (page version cant change
> then anymore)" Can I even do this in a behavior?
>
> Cemal Bayramoglu wrote:
>> Warren,
>>
>> See MarkupContainer#visitChildren
>>
>> Regards - Cemal
>> jWeekend
>> OO & Java Technologies, Wicket
>> Consulting, Development, Training
>> http://jWeekend.com
>>
>> On 15 April 2010 18:44, Warren Bell <Wa...@clarksnutrition.com> wrote:
>>> Is there a way to add attributes to child components in a behavior that
>>> is added to a page? I want to create a behavior that is added to a page
>>> that adds some js to the header and then adds some js in an onfocus
>>> attribute of each child form component on the page. I have the list of
>>> child form components, but can't figure out how to add the attribute to
>>> the components.
>>>
>>> Warren
>>>
>>
>> ---------------------------------------------------------------------
>> 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: Adding attributes to child components in a behavior.
Posted by Warren Bell <wa...@gmail.com>.
I have that figured out, I just don't know how to add the attribute to
each component. I can't add a behavior, since "Cannot modify component
hierarchy after render phase has started (page version cant change then
anymore)" Can I even do this in a behavior?
Cemal Bayramoglu wrote:
> Warren,
>
> See MarkupContainer#visitChildren
>
> Regards - Cemal
> jWeekend
> OO & Java Technologies, Wicket
> Consulting, Development, Training
> http://jWeekend.com
>
> On 15 April 2010 18:44, Warren Bell <Wa...@clarksnutrition.com> wrote:
>
>> Is there a way to add attributes to child components in a behavior that
>> is added to a page? I want to create a behavior that is added to a page
>> that adds some js to the header and then adds some js in an onfocus
>> attribute of each child form component on the page. I have the list of
>> child form components, but can't figure out how to add the attribute to
>> the components.
>>
>> Warren
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Thanks,
Warren Bell
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Adding attributes to child components in a behavior.
Posted by Cemal Bayramoglu <jW...@cabouge.com>.
Warren,
See MarkupContainer#visitChildren
Regards - Cemal
jWeekend
OO & Java Technologies, Wicket
Consulting, Development, Training
http://jWeekend.com
On 15 April 2010 18:44, Warren Bell <Wa...@clarksnutrition.com> wrote:
> Is there a way to add attributes to child components in a behavior that
> is added to a page? I want to create a behavior that is added to a page
> that adds some js to the header and then adds some js in an onfocus
> attribute of each child form component on the page. I have the list of
> child form components, but can't figure out how to add the attribute to
> the components.
>
> Warren
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org