On 3/9/11 2:18 AM, Maarten Billemont wrote:
On 09 Mar 2011, at 10:44, Gary Thomas wrote:

While a minority use-case, this allows for very elegant Wicket code when using 
Scala:

add(new Form[Person]("form", model) {
    add (new TextArea[String]("text", (getModel ->  "text")) {
        override def isVisible: Boolean = false
    })
})

Style is great when there are no issues involved with doing it.  If it turns 
out that adding components from the constructor is indeed dangerous when 
combined with other components (eg. in libraries) that use onInitialize then we 
should reconsider.

I think the best solution so far would be to not invoke onInitialize when 
adding components to a page, that would allow the constructor to be used still 
if the developer really wants to.

With regards to your Scala code, while I don't know any Scala whatsoever, 
wouldn't it be just as easy to do something like this:

add(new Form[Person]("form", model) {
    override def onInitialize: add (new TextArea[String]("text", (getModel ->  
"text")) {
        override def isVisible: Boolean = false
    })
})


Thanks for the reply -
Yes it would be as simple as that - but again, not quite as elegant (imho).

I admit my argument is pretty minor, but elegant code is a hallmark of an API or library that is designed well, and I think Wicket is great in that regard.

Scala aside, the current usage of add() from the constructor "just makes sense" to me, since you really are "constructing" the component. Fully understood there are valid concerns about the side effects of this design, but would love to see that resolved transparently if at all possible.

I'm not an expert on the internals, but am a very happy user of Wicket :-)

Thanks,
Gary

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to