You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@click.apache.org by Bob Schellink <sa...@gmail.com> on 2010/04/17 08:40:06 UTC
duplicate inserts
Currently, Click throws an exception if the same control is added multiple times to a Page or
Container. This ensures we don't accidentally have two controls with the same name, but it adds
usage problems for stateful Pages where we *do* want to replace existing controls and models. To
work with stateful pages we often end up with the following code:
private Field field;
public void onInit() {
if (!form.contains(field)) {
form.add(field);
}
}
or if you don't keep a reference to a control:
public void onInit() {
Field field = new Field();
if (!form.getControlMap().containsKey(field.getName())) {
container.add(field);
}
}
My feeling is that naming collisions within the same page/container is rather rare. So I propose we
change current behavior to replace the existing object instead of throwing an exception. If there is
a replacement we could log a message (in dev modes) that control x was replaced in container y,
providing some indication that a replacement took place.
regards
bob
Re: duplicate inserts
Posted by AndreyRybin <ap...@gmail.com>.
Very good idea.
My 5c:
- For stateless pages click can log WARNing in all modes except production
(for stateless pages - duplicate looks like real mistake).
For stateful pages - info (or warn) in debug/trace mode.
- Javadoc should have explanation how prevent replacement (your examples
earlier)
--
View this message in context: http://n2.nabble.com/duplicate-inserts-tp4916692p4929500.html
Sent from the click-development mailing list archive at Nabble.com.