brabec
brabec

Reputation: 4730

Wicket - can you specify markups IDs for elements inside repeaters?

I'm having a hard time testing our Wicket application using Selenium because of the random markup ids.

For individual elements, I can use abc.setOutputMarkupId(true).setMarkupId("myId") to set their markup id explicitly.
But what if the element is added dynamically using a repeater (like ListView)? Is there a way to specify how the markup id sequence should look like?

Upvotes: 3

Views: 5940

Answers (2)

osdamv
osdamv

Reputation: 3583

as Andrei told that its possible but dangerous. setMarkupId doc:

Retrieves id by which this component is represented within the markup. This is either the id attribute set explicitly via a call to org.apache.wicket.Component.setMarkupId(java.lang.String), id attribute defined in the markup, or an automatically generated id - in that order. If no explicit id is set this function will generate an id value that will be unique in the page. This is the preferred way as there is no chance of id collision. http://www.kiwidoc.com/java/l/p/org.apache.wicket/wicket/1.4.0/p/org.apache.wicket/c/Component#top

and also you cant get the markup id with getMarkupId()

Upvotes: 1

Shivan Dragon
Shivan Dragon

Reputation: 15219

Well, can't you do the same thing with ListView? If you make your own ListView implementation, and then in the populateItem(final ListItem<?> listItem) method, on that respective listItem you do:

listItem.setOutputMarkupId(true); // write id attribute of element to html
listItem.setMarkupId("id"+i);

where i is some index you initialize in the ListView's constructor or something?

Upvotes: 1

Related Questions