On Mon, 29 Sep 2008, Michael Sparer wrote:
> possible yes, recommended, no i'd say :-)
> 
> if you need specific values from MyPanel then pass it via constructor, if
> you need values/attributes on component (e.g. isVisible) level use
> getParent()

I think that getParent() is generally a bad idea, because it
adds too much coupling and makes testing difficult.

Whenever you can simply pass dependencies in a constructor,
or set them from the parent after construction, that's 
probably the best way. You can even make the object 
references updateable by passing and storing a model 
wrapping the object instead of the object itself.


The visitor-based event mechanisms discussed in WICKET-1312
could be used to some extent, or you can use the visitors 
for pull-style stuff as well as my colleague did recently

    public interface SelectedUserSource {
        IModel<User> selectedUser();
    }
    
    public class UserProfile extends Panel implements SelectedUserSource {... 

and in calling component

    private IModel<User> findSelectedUser() {
        return (IModel<User>) getPage().visitChildren(SelectedUserSource.class, 
new IVisitor() {
            public Object component(Component component) {
                return ((SelectedUserSource) component).selectedUser();
            }
        }):
    }


Having the dependent class as an inner class of the dependee 
makes sense in trivial cases but is often just a more explicit
way of doing getParent(). I think that we desperately need to
find ways to make our UI (Wicket) code good object-oriented
code. I for one find myself often putting way too much stuff 
and coupling in a component class. 

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to