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

Reply via email to