Question

In my Wicket application I use a Tree object. My goal is to show only one level at the same time, which means expanding the root node will hide the root node and display the first level of subnodes. Nodes without child nodes should also get a different css styling.

To accomplish this, I use the following code:

Tree tree = new Tree("tree", customModel()) {
            @Override
            protected void onNodeLinkClicked(AjaxRequestTarget target, TreeNode node) {
                System.out.println("selected value  "+ node.toString());
            } 
};

The problem is that I want to use Javascript to add css classes and hide nodes. However, for this I need the wicket:id of a clicked node. I have no idea to retrieve this id, can someone help me with this?

Was it helpful?

Solution

node.getMarkupId() gives you the id the node will have in the html, which is often different from the wicket:id.

wicket:id corresponds to the component id in the javacode (in the case of new Label("blah")) the id is "blah".

In the generated html this might become <span id="blah12f4"...

node.getMarkupId() will return "blah12f4".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top