You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sam Hough <sa...@redspr.com> on 2007/09/27 13:51:57 UTC

Reach into a component to change XML attribute

I've got my own wiz bang extension of RepeatingView and I want to add class
attributes "last", "first" to the children for the HTML monkey.

Is the best way to add an AttributeAppender to each child Component that
uses an IModel to get the class? Maybe in beforeOnRender I can't see an
onChildAttach or onChildRemove method or anything like that. All my ideas
seem a bit heavy and clumsy.

This must be somewhere in existing code or Nabble but I'm afraid I couldn't
see it. Sorry.
-- 
View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12919632
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: Reach into a component to change XML attribute

Posted by Sam Hough <sa...@redspr.com>.
Also didn't know about isTemporary. Looks very nice and simple. Guess I need
to test what isTemporary does if a subsequent Ajax request asks for a single
child to be rendered, I don't think RepeatingViews are eligible for an
AjaxTarget.

Many thanks Kent. Looks lovely shiny code.



Kent Tong wrote:
> 
> 
> Sam Hough wrote:
>> 
>> Your still breaking my requirement that this behaviour is encapsulated
>> within MyFancyRepeatingView ;) I really do appreciate all your code and I
>> think I'm learning a lot even if I sound horribly ungrateful. I'm warming
>> to every child component having a special behaviour object. Although it
>> seems expensive does show nice encapsulation.
>> 
>> How about MyFancyRepeatingView has a singleton behaviour object that it
>> checks is attached to all its children (should be quick as identity
>> operation - in childIterator). Requires only single instance for whole
>> application... I might be able to convince the HTML monkey that he only
>> needs class="first" so I don't need to iterate through all the siblings.
>> 
> 
> Then add the behaviors in onBeforeRender():
> 
> public class MyRepeatingView extends RepeatingView {
> 	public MyRepeatingView(String id) {
> 		super(id);
> 	}
> 	protected void onBeforeRender() {
> 		super.onBeforeRender();
> 		int idx = 0;
> 		Iterator iter = iterator();
> 		while (iter.hasNext()) {
> 			Component child = (Component) iter.next();
> 			if (idx == 0 || idx == size() - 1) {
> 				child.add(new AttributeModifier("class", true, new Model(
> 						idx == 0 ? "first" : "last")) {
> 					public boolean isTemporary() {
> 						return true;
> 					}
> 				});
> 			}
> 			idx++;
> 		}
> 	}
> }
> 

-- 
View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12965606
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: Reach into a component to change XML attribute

Posted by Kent Tong <ke...@cpttm.org.mo>.

Sam Hough wrote:
> 
> Your still breaking my requirement that this behaviour is encapsulated
> within MyFancyRepeatingView ;) I really do appreciate all your code and I
> think I'm learning a lot even if I sound horribly ungrateful. I'm warming
> to every child component having a special behaviour object. Although it
> seems expensive does show nice encapsulation.
> 
> How about MyFancyRepeatingView has a singleton behaviour object that it
> checks is attached to all its children (should be quick as identity
> operation - in childIterator). Requires only single instance for whole
> application... I might be able to convince the HTML monkey that he only
> needs class="first" so I don't need to iterate through all the siblings.
> 

Then add the behaviors in onBeforeRender():

public class MyRepeatingView extends RepeatingView {
	public MyRepeatingView(String id) {
		super(id);
	}
	protected void onBeforeRender() {
		super.onBeforeRender();
		int idx = 0;
		Iterator iter = iterator();
		while (iter.hasNext()) {
			Component child = (Component) iter.next();
			if (idx == 0 || idx == size() - 1) {
				child.add(new AttributeModifier("class", true, new Model(
						idx == 0 ? "first" : "last")) {
					public boolean isTemporary() {
						return true;
					}
				});
			}
			idx++;
		}
	}
}
-- 
View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12965598
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: Reach into a component to change XML attribute

Posted by Sam Hough <sa...@redspr.com>.
Ooh. I've not seen the trick of passing int[] to make it pass by reference
semantics! 

Not that I've got hero worship or anything now but why visit children rather
than Component.iterator?

Your still breaking my requirement that this behaviour is encapsulated
within MyFancyRepeatingView ;) I really do appreciate all your code and I
think I'm learning a lot even if I sound horribly ungrateful. I'm warming to
every child component having a special behaviour object. Although it seems
expensive does show nice encapsulation.

How about MyFancyRepeatingView has a singleton behaviour object that it
checks is attached to all its children (should be quick as identity
operation - in childIterator). Requires only single instance for whole
application... I might be able to convince the HTML monkey that he only
needs class="first" so I don't need to iterate through all the siblings.

Anyway, many thanks Kent.


Kent Tong wrote:
> 
> 
> Sam Hough wrote:
>> 
>> I'm full of cold so probably being very thick but that doesn't work for
>> RepeatingView does it as it implies notification of objects being
>> attached to a parent :(  It looks very clever but I'm not having one of
>> those "god that is so simple why didn't I think of that" moments... Have
>> you been following the "remove final for add, remove, removeAll" etc
>> thread? Seems like I could do a simple (if ugly) and efficient version
>> that those changes. To add to the horror I've got my own add(int i,
>> Component c) method , that igor didn't like, that I want to honour.
>> 
> 
> The code below seems to work for a RepeatingView. Of course it is a hack
> as it depends on the
> order in which the children are visited. However, it doesn't depend on
> notification of objects
> being attached to the parent. The bind() method is called when the
> behavior is added to the
> component.
> 
> public class Home extends WebPage {
> 	private static class BoundHighlighter extends AttributeModifier {
> 		private Component owner;
> 
> 		public BoundHighlighter() {
> 			super("class", true, null);
> 		}
> 		protected String newValue(String currentValue, String replacementValue)
> {
> 			int idx = getItemIndex();
> 			return idx == 0 ? "first" : (idx == getItemCount() - 1 ? "last"
> 					: null);
> 		}
> 		public void bind(Component component) {
> 			super.bind(component);
> 			this.owner = component;
> 		}
> 		private int getItemIndex() {
> 			final int[] idx = { -1 };
> 			Object result = owner.getParent().visitChildren(new IVisitor() {
> 				public Object component(Component component) {
> 					idx[0]++;
> 					return component == owner ? idx[0]
> 							: CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
> 				}
> 			});
> 			return (Integer) result;
> 		}
> 		private int getItemCount() {
> 			return owner.getParent().size();
> 		}
> 	}
> 
> 	public Home() {
> 		RepeatingView view = new RepeatingView("view");
> 		view.add(new Label("x", "a").add(new BoundHighlighter()));
> 		view.add(new Label("y", "b").add(new BoundHighlighter()));
> 		view.add(new Label("z", "c").add(new BoundHighlighter()));
> 		view.add(new Label("t", "d").add(new BoundHighlighter()));
> 		add(view);
> 	}
> }
> 

-- 
View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12964994
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: Reach into a component to change XML attribute

Posted by Kent Tong <ke...@cpttm.org.mo>.

Sam Hough wrote:
> 
> I'm full of cold so probably being very thick but that doesn't work for
> RepeatingView does it as it implies notification of objects being attached
> to a parent :(  It looks very clever but I'm not having one of those "god
> that is so simple why didn't I think of that" moments... Have you been
> following the "remove final for add, remove, removeAll" etc thread? Seems
> like I could do a simple (if ugly) and efficient version that those
> changes. To add to the horror I've got my own add(int i, Component c)
> method , that igor didn't like, that I want to honour.
> 

The code below seems to work for a RepeatingView. Of course it is a hack as
it depends on the
order in which the children are visited. However, it doesn't depend on
notification of objects
being attached to the parent. The bind() method is called when the behavior
is added to the
component.

public class Home extends WebPage {
	private static class BoundHighlighter extends AttributeModifier {
		private Component owner;

		public BoundHighlighter() {
			super("class", true, null);
		}
		protected String newValue(String currentValue, String replacementValue) {
			int idx = getItemIndex();
			return idx == 0 ? "first" : (idx == getItemCount() - 1 ? "last"
					: null);
		}
		public void bind(Component component) {
			super.bind(component);
			this.owner = component;
		}
		private int getItemIndex() {
			final int[] idx = { -1 };
			Object result = owner.getParent().visitChildren(new IVisitor() {
				public Object component(Component component) {
					idx[0]++;
					return component == owner ? idx[0]
							: CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
				}
			});
			return (Integer) result;
		}
		private int getItemCount() {
			return owner.getParent().size();
		}
	}

	public Home() {
		RepeatingView view = new RepeatingView("view");
		view.add(new Label("x", "a").add(new BoundHighlighter()));
		view.add(new Label("y", "b").add(new BoundHighlighter()));
		view.add(new Label("z", "c").add(new BoundHighlighter()));
		view.add(new Label("t", "d").add(new BoundHighlighter()));
		add(view);
	}
}
-- 
View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12961809
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: Reach into a component to change XML attribute

Posted by Johan Compagner <jc...@gmail.com>.
why wouldnt that behavior work? the newValue call is only being called
when rendered. so it ha a parent. Besides that what does overide
add/remove gain you? you then want to check there if it is the first
an last? Depending on the reuse of components (items) and if the data
(list) can change this could go wrong quickly.

On 9/29/07, Sam Hough <sa...@redspr.com> wrote:
>
> I'm full of cold so probably being very thick but that doesn't work for
> RepeatingView does it as it implies notification of objects being attached
> to a parent :(  It looks very clever but I'm not having one of those "god
> that is so simple why didn't I think of that" moments... Have you been
> following the "remove final for add, remove, removeAll" etc thread? Seems
> like I could do a simple (if ugly) and efficient version that those changes.
> To add to the horror I've got my own add(int i, Component c) method , that
> igor didn't like, that I want to honour.
>
> Sorry if that sounds grumpy but I'm a miserable git when I've got a cold/man
> flu.
>
>
> Kent Tong wrote:
> >
> >
> > Sam Hough wrote:
> >>
> >> In my ignorance it seems tough to make that work the second time if the
> >> list has changed. It is also less pretty as the only extension points I
> >> have are renderIterator and renderChild. I can think of nasty hacks like
> >> using IdentityHashMap to hold onto Components I've already added an
> >> AttributeAppender (the HTML monkey is class happy) to...
> >>
> >
> > Try using a modifier like this:
> > 	private static class BoundHighlighter extends AttributeModifier {
> > 		private Component owner;
> >
> > 		public BoundHighlighter() {
> > 			super("class", true, null);
> > 		}
> > 		protected String newValue(String currentValue, String replacementValue)
> > {
> > 			int idx = getItemIndex();
> > 			return idx == 0 ? "first" : (idx == getItemCount() - 1 ? "last"
> > 					: null);
> > 		}
> > 		public void bind(Component component) {
> > 			super.bind(component);
> > 			this.owner = component;
> > 		}
> > 		private int getItemIndex() {
> > 			return getItem().getIndex();
> > 		}
> > 		private Item getItem() {
> > 			Component parent = owner.getParent();
> > 			while (!(parent instanceof Item)) {
> > 				parent = parent.getParent();
> > 			}
> > 			return (Item) parent;
> > 		}
> > 		private int getItemCount() {
> > 			return getItem().getParent().size();
> > 		}
> > 	}
> >
> > The code below uses it for a Label contained in a repeater Item:
> >
> > 	public Home() {
> > 		RefreshingView view = new RefreshingView("view") {
> > 			protected Iterator getItemModels() {
> > 				List<IModel> models = new ArrayList<IModel>();
> > 				int n = 2+new Random().nextInt(10);
> > 				for (int i = 0; i < n; i++) {
> > 					models.add(new Model(i));
> > 				}
> > 				return models.iterator();
> > 			}
> > 			protected void populateItem(Item item) {
> > 				item.add(new Label("label", item.getModel())
> > 						.add(new BoundHighlighter()));
> > 			}
> > 		};
> > 		add(view);
> > 	}
> >
>
> --
> View this message in context:
> http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12954716
> 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
>
>

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


Re: Reach into a component to change XML attribute

Posted by Sam Hough <sa...@redspr.com>.
I'm full of cold so probably being very thick but that doesn't work for
RepeatingView does it as it implies notification of objects being attached
to a parent :(  It looks very clever but I'm not having one of those "god
that is so simple why didn't I think of that" moments... Have you been
following the "remove final for add, remove, removeAll" etc thread? Seems
like I could do a simple (if ugly) and efficient version that those changes.
To add to the horror I've got my own add(int i, Component c) method , that
igor didn't like, that I want to honour.

Sorry if that sounds grumpy but I'm a miserable git when I've got a cold/man
flu.
 

Kent Tong wrote:
> 
> 
> Sam Hough wrote:
>> 
>> In my ignorance it seems tough to make that work the second time if the
>> list has changed. It is also less pretty as the only extension points I
>> have are renderIterator and renderChild. I can think of nasty hacks like
>> using IdentityHashMap to hold onto Components I've already added an
>> AttributeAppender (the HTML monkey is class happy) to...
>> 
> 
> Try using a modifier like this:
> 	private static class BoundHighlighter extends AttributeModifier {
> 		private Component owner;
> 
> 		public BoundHighlighter() {
> 			super("class", true, null);
> 		}
> 		protected String newValue(String currentValue, String replacementValue)
> {
> 			int idx = getItemIndex();
> 			return idx == 0 ? "first" : (idx == getItemCount() - 1 ? "last"
> 					: null);
> 		}
> 		public void bind(Component component) {
> 			super.bind(component);
> 			this.owner = component;
> 		}
> 		private int getItemIndex() {
> 			return getItem().getIndex();
> 		}
> 		private Item getItem() {
> 			Component parent = owner.getParent();
> 			while (!(parent instanceof Item)) {
> 				parent = parent.getParent();
> 			}
> 			return (Item) parent;
> 		}
> 		private int getItemCount() {
> 			return getItem().getParent().size();
> 		}
> 	}
> 
> The code below uses it for a Label contained in a repeater Item:
> 
> 	public Home() {
> 		RefreshingView view = new RefreshingView("view") {
> 			protected Iterator getItemModels() {
> 				List<IModel> models = new ArrayList<IModel>();
> 				int n = 2+new Random().nextInt(10);
> 				for (int i = 0; i < n; i++) {
> 					models.add(new Model(i));
> 				}
> 				return models.iterator();
> 			}
> 			protected void populateItem(Item item) {
> 				item.add(new Label("label", item.getModel())
> 						.add(new BoundHighlighter()));
> 			}
> 		};
> 		add(view);
> 	}
> 

-- 
View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12954716
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: Reach into a component to change XML attribute

Posted by Kent Tong <ke...@cpttm.org.mo>.

Sam Hough wrote:
> 
> In my ignorance it seems tough to make that work the second time if the
> list has changed. It is also less pretty as the only extension points I
> have are renderIterator and renderChild. I can think of nasty hacks like
> using IdentityHashMap to hold onto Components I've already added an
> AttributeAppender (the HTML monkey is class happy) to...
> 

Try using a modifier like this:
	private static class BoundHighlighter extends AttributeModifier {
		private Component owner;

		public BoundHighlighter() {
			super("class", true, null);
		}
		protected String newValue(String currentValue, String replacementValue) {
			int idx = getItemIndex();
			return idx == 0 ? "first" : (idx == getItemCount() - 1 ? "last"
					: null);
		}
		public void bind(Component component) {
			super.bind(component);
			this.owner = component;
		}
		private int getItemIndex() {
			return getItem().getIndex();
		}
		private Item getItem() {
			Component parent = owner.getParent();
			while (!(parent instanceof Item)) {
				parent = parent.getParent();
			}
			return (Item) parent;
		}
		private int getItemCount() {
			return getItem().getParent().size();
		}
	}

The code below uses it for a Label contained in a repeater Item:

	public Home() {
		RefreshingView view = new RefreshingView("view") {
			protected Iterator getItemModels() {
				List<IModel> models = new ArrayList<IModel>();
				int n = 2+new Random().nextInt(10);
				for (int i = 0; i < n; i++) {
					models.add(new Model(i));
				}
				return models.iterator();
			}
			protected void populateItem(Item item) {
				item.add(new Label("label", item.getModel())
						.add(new BoundHighlighter()));
			}
		};
		add(view);
	}
-- 
View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12951781
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: Reach into a component to change XML attribute

Posted by Sam Hough <sa...@redspr.com>.
Is this a common enough requirement to add something like IdentityHashMap for
behaviours so from another component you can do getBehaviours(this) to
retrieve the AttributeModifier or named behaviours e.g.
getBehaviourById("com.company.thingy.Repeater.ClassHack")?

The latter might also be a nice way of marking components for various uses. 


Sam Hough wrote:
> 
> That seems a bit ugly as I want this rule to apply to all components I put
> into MyRepeatingView.
> 
> I'm trying to have MyLink, MyPanel, MyBlah so could add some standard
> behaviour but seems like wrong way around and will obviously break if
> somebody puts vanilla wicket component in.
> 
> :wq
> 
> 
> Al Maw wrote:
>> 
>> You can override onComponentTag for the component itself, if that's an 
>> option. Call super.onComponentTag(...) then tag.put("class", "foo") or 
>> whatever it is.
>> 
>> Regards,
>> 
>> Al
>> 
>> Sam Hough wrote:
>>> In my ignorance it seems tough to make that work the second time if the
>>> list
>>> has changed. It is also less pretty as the only extension points I have
>>> are
>>> renderIterator and renderChild. I can think of nasty hacks like using
>>> IdentityHashMap to hold onto Components I've already added an
>>> AttributeAppender (the HTML monkey is class happy) to...
>>> 
>>> If I can't hook into all child add/remove events and looking for my
>>> attributeappender in each component is a bit slow seems like the only
>>> option.
>>> 
>>> 
>>> Martijn Dashorst wrote:
>>>> This:
>>>>
>>>> Component first = null;
>>>> Component last = null;
>>>> for(Foo foo : foos) {
>>>>     last = new Component(view.newChildId());
>>>>     if(first == null) first = last;
>>>>     view.add(last);
>>>> }
>>>>
>>>> first.add(new SimpleAttributeModifier("class", "first"));
>>>> last.add(new SimpleAttributeModifier("class", "last"));
>>>>
>>>> doesn't work?
>>>>
>>>> Martijn
>>>>
>>>> On 9/27/07, Sam Hough <sa...@redspr.com> wrote:
>>>>> I've got my own wiz bang extension of RepeatingView and I want to add
>>>>> class
>>>>> attributes "last", "first" to the children for the HTML monkey.
>>>>>
>>>>> Is the best way to add an AttributeAppender to each child Component
>>>>> that
>>>>> uses an IModel to get the class? Maybe in beforeOnRender I can't see
>>>>> an
>>>>> onChildAttach or onChildRemove method or anything like that. All my
>>>>> ideas
>>>>> seem a bit heavy and clumsy.
>>>>>
>>>>> This must be somewhere in existing code or Nabble but I'm afraid I
>>>>> couldn't
>>>>> see it. Sorry.
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12919632
>>>>> 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
>>>>>
>>>>>
>>>>
>>>> -- 
>>>> Buy Wicket in Action: http://manning.com/dashorst
>>>> Apache Wicket 1.3.0-beta3 is released
>>>> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta3/
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12936562
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: Reach into a component to change XML attribute

Posted by Sam Hough <sa...@redspr.com>.
That seems a bit ugly as I want this rule to apply to all components I put
into MyRepeatingView.

I'm trying to have MyLink, MyPanel, MyBlah so could add some standard
behaviour but seems like wrong way around and will obviously break if
somebody puts vanilla wicket component in.

:wq


Al Maw wrote:
> 
> You can override onComponentTag for the component itself, if that's an 
> option. Call super.onComponentTag(...) then tag.put("class", "foo") or 
> whatever it is.
> 
> Regards,
> 
> Al
> 
> Sam Hough wrote:
>> In my ignorance it seems tough to make that work the second time if the
>> list
>> has changed. It is also less pretty as the only extension points I have
>> are
>> renderIterator and renderChild. I can think of nasty hacks like using
>> IdentityHashMap to hold onto Components I've already added an
>> AttributeAppender (the HTML monkey is class happy) to...
>> 
>> If I can't hook into all child add/remove events and looking for my
>> attributeappender in each component is a bit slow seems like the only
>> option.
>> 
>> 
>> Martijn Dashorst wrote:
>>> This:
>>>
>>> Component first = null;
>>> Component last = null;
>>> for(Foo foo : foos) {
>>>     last = new Component(view.newChildId());
>>>     if(first == null) first = last;
>>>     view.add(last);
>>> }
>>>
>>> first.add(new SimpleAttributeModifier("class", "first"));
>>> last.add(new SimpleAttributeModifier("class", "last"));
>>>
>>> doesn't work?
>>>
>>> Martijn
>>>
>>> On 9/27/07, Sam Hough <sa...@redspr.com> wrote:
>>>> I've got my own wiz bang extension of RepeatingView and I want to add
>>>> class
>>>> attributes "last", "first" to the children for the HTML monkey.
>>>>
>>>> Is the best way to add an AttributeAppender to each child Component
>>>> that
>>>> uses an IModel to get the class? Maybe in beforeOnRender I can't see an
>>>> onChildAttach or onChildRemove method or anything like that. All my
>>>> ideas
>>>> seem a bit heavy and clumsy.
>>>>
>>>> This must be somewhere in existing code or Nabble but I'm afraid I
>>>> couldn't
>>>> see it. Sorry.
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12919632
>>>> 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
>>>>
>>>>
>>>
>>> -- 
>>> Buy Wicket in Action: http://manning.com/dashorst
>>> Apache Wicket 1.3.0-beta3 is released
>>> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta3/
>>>
>>> ---------------------------------------------------------------------
>>> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12921571
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: Reach into a component to change XML attribute

Posted by Al Maw <wi...@almaw.com>.
You can override onComponentTag for the component itself, if that's an 
option. Call super.onComponentTag(...) then tag.put("class", "foo") or 
whatever it is.

Regards,

Al

Sam Hough wrote:
> In my ignorance it seems tough to make that work the second time if the list
> has changed. It is also less pretty as the only extension points I have are
> renderIterator and renderChild. I can think of nasty hacks like using
> IdentityHashMap to hold onto Components I've already added an
> AttributeAppender (the HTML monkey is class happy) to...
> 
> If I can't hook into all child add/remove events and looking for my
> attributeappender in each component is a bit slow seems like the only
> option.
> 
> 
> Martijn Dashorst wrote:
>> This:
>>
>> Component first = null;
>> Component last = null;
>> for(Foo foo : foos) {
>>     last = new Component(view.newChildId());
>>     if(first == null) first = last;
>>     view.add(last);
>> }
>>
>> first.add(new SimpleAttributeModifier("class", "first"));
>> last.add(new SimpleAttributeModifier("class", "last"));
>>
>> doesn't work?
>>
>> Martijn
>>
>> On 9/27/07, Sam Hough <sa...@redspr.com> wrote:
>>> I've got my own wiz bang extension of RepeatingView and I want to add
>>> class
>>> attributes "last", "first" to the children for the HTML monkey.
>>>
>>> Is the best way to add an AttributeAppender to each child Component that
>>> uses an IModel to get the class? Maybe in beforeOnRender I can't see an
>>> onChildAttach or onChildRemove method or anything like that. All my ideas
>>> seem a bit heavy and clumsy.
>>>
>>> This must be somewhere in existing code or Nabble but I'm afraid I
>>> couldn't
>>> see it. Sorry.
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12919632
>>> 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
>>>
>>>
>>
>> -- 
>> Buy Wicket in Action: http://manning.com/dashorst
>> Apache Wicket 1.3.0-beta3 is released
>> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta3/
>>
>> ---------------------------------------------------------------------
>> 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: Reach into a component to change XML attribute

Posted by Sam Hough <sa...@redspr.com>.
In my ignorance it seems tough to make that work the second time if the list
has changed. It is also less pretty as the only extension points I have are
renderIterator and renderChild. I can think of nasty hacks like using
IdentityHashMap to hold onto Components I've already added an
AttributeAppender (the HTML monkey is class happy) to...

If I can't hook into all child add/remove events and looking for my
attributeappender in each component is a bit slow seems like the only
option.


Martijn Dashorst wrote:
> 
> This:
> 
> Component first = null;
> Component last = null;
> for(Foo foo : foos) {
>     last = new Component(view.newChildId());
>     if(first == null) first = last;
>     view.add(last);
> }
> 
> first.add(new SimpleAttributeModifier("class", "first"));
> last.add(new SimpleAttributeModifier("class", "last"));
> 
> doesn't work?
> 
> Martijn
> 
> On 9/27/07, Sam Hough <sa...@redspr.com> wrote:
>>
>> I've got my own wiz bang extension of RepeatingView and I want to add
>> class
>> attributes "last", "first" to the children for the HTML monkey.
>>
>> Is the best way to add an AttributeAppender to each child Component that
>> uses an IModel to get the class? Maybe in beforeOnRender I can't see an
>> onChildAttach or onChildRemove method or anything like that. All my ideas
>> seem a bit heavy and clumsy.
>>
>> This must be somewhere in existing code or Nabble but I'm afraid I
>> couldn't
>> see it. Sorry.
>> --
>> View this message in context:
>> http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12919632
>> 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
>>
>>
> 
> 
> -- 
> Buy Wicket in Action: http://manning.com/dashorst
> Apache Wicket 1.3.0-beta3 is released
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta3/
> 
> ---------------------------------------------------------------------
> 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/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12919890
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: Reach into a component to change XML attribute

Posted by Martijn Dashorst <ma...@gmail.com>.
This:

Component first = null;
Component last = null;
for(Foo foo : foos) {
    last = new Component(view.newChildId());
    if(first == null) first = last;
    view.add(last);
}

first.add(new SimpleAttributeModifier("class", "first"));
last.add(new SimpleAttributeModifier("class", "last"));

doesn't work?

Martijn

On 9/27/07, Sam Hough <sa...@redspr.com> wrote:
>
> I've got my own wiz bang extension of RepeatingView and I want to add class
> attributes "last", "first" to the children for the HTML monkey.
>
> Is the best way to add an AttributeAppender to each child Component that
> uses an IModel to get the class? Maybe in beforeOnRender I can't see an
> onChildAttach or onChildRemove method or anything like that. All my ideas
> seem a bit heavy and clumsy.
>
> This must be somewhere in existing code or Nabble but I'm afraid I couldn't
> see it. Sorry.
> --
> View this message in context: http://www.nabble.com/Reach-into-a-component-to-change-XML-attribute-tf4527906.html#a12919632
> 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
>
>


-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.0-beta3 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta3/

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