Page - addModel() -> IllegalArgumentException ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Page - addModel() -> IllegalArgumentException ?

Ahmed Mohombe
Hi,

adding a model with the same key in a Page throws an IllegalArgumentException.

IMHO this is not too developer friendly - it would be better just to override the existing element,
or at least there should be a way to turn such a override functionality on, and just log the
'conflicts' instead of throwing exceptions.

A very common scenario:
- For many pages, some values can be stetted in the decorator/Border (common for all of them, and
independent from the number of pages).
- If only a few pages are the exception from the rule, it would be easier in those pages just
to have the override effect for the 'different values' - e.g. the title does not respect the same
rule like default for all the pages, etc..

Thanks in advance,

Ahmed.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Click-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/click-development
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Page - addModel() -> IllegalArgumentException ?

Malcolm Edgar-2
I think this bit of a trade off, as there are a couple of scenarios here:

#1 - Its a programming error, adding the different object to a model with the
     same name. This has highlighted many of my errors.

#2 - Its a genuine programming technique, where you may override a prexisting
     model value. In these cases you can delete the existing value before hand:

     if (getModel().contains("table")) {
        getModel().remove("table");
     }
     addModel("table", table);
 
If you support #2 and only log when you are overwriting existing values, its not
very obvious as to whats happening and you can introduce bugs when accidently
overwriting an existing value.

regards Malcolm Edgar



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Click-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/click-development
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Page - addModel() -> IllegalArgumentException ?

Ahmed Mohombe
> I think this bit of a trade off, as there are a couple of scenarios here:
>
> #1 - Its a programming error, adding the different object to a model with the
>      same name. This has highlighted many of my errors.
>
> #2 - Its a genuine programming technique, where you may override a prexisting
>      model value. In these cases you can delete the existing value before hand:
>
>      if (getModel().contains("table")) {
>         getModel().remove("table");
>      }
>      addModel("table", table);
>  
> If you support #2 and only log when you are overwriting existing values, its not
> very obvious as to whats happening and you can introduce bugs when accidently
> overwriting an existing value.
Hmm, you are right, for new users it's even better so (and they don't get this from
too many other frameworks).
Because the "copy and paste" bug pattern is still very common these days case #1
might happen ofter than I thought.

Anyway, my idea was to log (with a warning) these situations, but it can very
well happen that many developers just ignore logs.

If we go from the 80/20 rule, than indeed #2 it's the wanted "exception from the
rule", and in this case the developer writes 4 LOC instead of 1, but it falls in the 20%,
so you are right.

I suppose, even for programming, it's always a compromise between comfort and security :).
To have both, the framework would need to be very complicated (I guess, that's where
Tapestry is heading to), and that would better go in some tool instead of the framework
itself.

For IntelliJ IDE , one could write a 'inspection' that checks if a parent has added a
model with the same name (if using pure strings), and if so, to expand the:
"addModel("table", table)" to the 4 LOC from #2 :).

Thank you for your response,

Ahmed.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Click-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/click-development
Loading...