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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]