I have a Panel that I’m using to display information about a location. I have a page that I’m using to display information about a Delivery Appointment that involves two locations. My Delivery page includes the Location Panel twice – once for the Origin and once for the Destination. This example has been simplified so the Location only has a single property of Name.
Question:
What is the best way to set the Markup ID for the Name (and other properties) of both locations while keeping them unique?
Sample Code
LocationPanel.java
public class LocationPanel extends BasePanel {
public LocationPanel(String id, String locCode) {
super(id);
init(locCode);
}
private void init(String locCode) {
LocationInfo locModel = new LocationInfo(locCode + " Location");
CompoundPropertyModel model = new CompoundPropertyModel(locModel);
Label name = new Label("name");
setDefaultModel(model);
add(name);
}
}
LocationPanel.html
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<h3><span wicket:id="name">SAMPLE location</span></h3>
</wicket:panel>
</body>
</html>
SetDeliveryAppointment.java
public class SetDeliveryAppointment extends BaseWebPage{
public SetDeliveryAppointment(String id) {
super(id);
init();
}
private void init() {
Panel origin = new RampLocationInformationPanel("origin", "LAX");
Panel dest = new RampLocationInformationPanel("dest", "DAL");
WebMarkupContainer delivery = new WebMarkupContainer("delivery");
delivery.add(origin);
delivery.add(dest);
add(delivery);
}
}
SetDeliveryAppointment.html
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:extend>
<wicket:container wicket:id="delivery">
<div wicket:id="origin"></div>
<div wicket:id="dest"></div>
</wicket:container>
</wicket:extend>
</body>
</html>
The Goal:
So what I’d like to see in the resulting HTML is as follows
Final HTML View Source Goal
<html>
<body>
<div id="origin">
<!-- The exact id doesn't matter -->
<!-- as long as 'origin' and 'name' are contained in it -->
<h3><span id="origin_name">LAX location</span></h3>
</div>
<div id="dest">
<h3><span id="dest_name">DAL location</span></h3>
</div>
</body>
</html>
Bonus:
This is really a cross-cutting concern. We’d ideally like every Wicket component to get a unique ID, but we want it to be predictable based on the rules we prescribe. The perfect solution would address this.
Disclaimer: I’m new to Wicket, so go easy on me if this is a silly question
When you use JS, you should not use #id (e.g. as in jQuery use relative selectors) or generate a javascript snippet where you will pass
component.getMarkupId().Not sure about selenium, probably better is to use the wicket test framework (it’s quite powerful).