Question

I'm fairly new to Wicket. I like its core principle but I'm also missing a, in my opinion, pretty crucial feature. What I'd like to do:

Define a component

class MyPanel extends Panel { 
   ... 
} 

Define its markup

<html xmls:wicket....>
    <wicket:panel>
        This is my panel <br />
        <wicket:subComponents/>
    </wicket:panel>
</html>

(Obvisouly, I made <wicket:subComponents\> up)

Define a Page

class MyPage extends WebPage { 

    public MyPage() { 
        super(); 
        MyPanel panel = new MyPanel("myPanel")); 
        panel.add(new Component...); 
        panel.add(new Component...); 
        ... 
    } 
} 

As you see I'd like to nest components into other components without explicitly adding the nested components in the markup and specifying a wicket:id.(see second code snippet above)

That way I can map a Java class to a markup snippet (first and second snippet above) once and completely describe the whole markup of any page in Java just by building the component tree (see third code snippet above).

The question now is: Can it be done? If yes, how?

Was it helpful?

Solution

Why not just use a repeater for that:

<html xmls:wicket....>
    <wicket:panel>
        This is my panel <br />
        <div wicket:id="subComponents"></div>
    </wicket:panel>
</html>

class MyPanel extends Panel { 
    RepeatingView repeater;
    MyPanel() {
        add(repeater = new RepeatingView("subComponents");
    }

    public void addSub(Component component) {
        repeater.add(component);
    }
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top