if it was me just add() and should just replace if there is already one with that id if not then add. (and don't throw an error)
thats how 2.0 really worked. (and for example Swing also) johan On 4/1/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
should actually be called addOrReplace() :) -igor On 3/31/07, Matej Knopp <[EMAIL PROTECTED]> wrote: > > I'm fine with either too. > > -Matej > > On 3/31/07, Eelco Hillenius <[EMAIL PROTECTED]> wrote: > > That's an idea too. It's an extra method (not so nice) but more pricise > (nice). > > > > I'm fine with either. What do others think? > > > > Eelco > > > > > > On 3/31/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote: > > > or add a replaceOrAdd() method > > > > > > -igor > > > > > > > > > On 3/31/07, Eelco Hillenius <[EMAIL PROTECTED]> wrote: > > > > > > > > I'm backporting Wicket In Action's code currently, and stumbled upon > > > > something I really liked to be able to do in 2.0 which I can't do in > > > > the same way in 1.3. > > > > > > > > Consider this: > > > > > > > > void setContentPanel() { > > > > if (inEditMode) { > > > > new DiscountsEditList(this, "content"); > > > > } else { > > > > new DiscountsList(this, "content"); > > > > } > > > > } > > > > > > > > I'd like to be able to write that as: > > > > > > > > void setContentPanel() { > > > > if (inEditMode) { > > > > replace(new DiscountsEditList("content")); > > > > } else { > > > > replace(new DiscountsList("content")); > > > > } > > > > } > > > > > > > > However, there is this check in replace: > > > > > > > > // Add to map > > > > final Component replaced = put(child); > > > > > > > > // Look up to make sure it was already in > the map > > > > if (replaced == null) > > > > { > > > > throw new WicketRuntimeException( > > > > > exceptionMessage("Cannot > > > > replace a component which has not been > > > > added: id='" > > > > + > > > > child.getId() + "', component=" + child)); > > > > } > > > > > > > > so I'd have to do something like: > > > > > > > > if (get("content") != null) { > > > > replace(new DiscountsEditList("content")); > > > > } else { > > > > add(new DiscountsEditList("content")); > > > > } > > > > > > > > yech. I really don't see the added value of that check. I understand > > > > how it got in there, but when you think of it, what actual problem > > > > would this solve? Imo, we should just get rid of that check so that > > > > calling replace would be a simple add if the component wasn't added > > > > yet. > > > > > > > > Eelco > > > > > > > > > >