Haris Priganica
Haris Priganica

Reputation: 73

HTML Id Naming Convention in Java/WICKET for Automation and Design Purpose

The base Idea behind is to produce HTML ID that would have the following pattern ClassName_MethodName_ControlName and ClassName_MethodName_RepeaterName_RepeaterCounterZeroBased[999]_FeldControlName_FeldCounterZeroBased[999] that Backend Developers, Automation Engineer as well Designers and Fronted developers that are dealing with Bootstrap 3 and jQuery on the client side and we want to use a Naming Convention as a backbone. The same could be applied for any Software Development Technology.

In my opinion it would generate a unique set of IDs for HTML Elements, because you normally have controls with same name and same types just in different methods. It could appear in the same class but in different Methods. In that case they would be on the UI redundant, such as ProductID, ManufacturingID, OrderID with different provenience and meanings but as HTML Identifiers they are the same and we want to create Unique patterns for them.

As you know WICKET use Id to deal with its elements.

It that matter the obvious solution is to set:

Component.setOutputMarkupId(true); // set the HTML Id attribute
Component.setMarkupId("ClassName_MethodName_ControlName"); // Unique id attribute

but Instead the challenge is to produce them dynamically. My Idea was to do it overriding the onConfigure event in WICKET's Java part and to actually place it in COMMON project that would be available for all other Projects. What is in your opinion the best practice and solution?

The more challenging problem here might be: how do you want to generate those IDs? For frontend testing purposes I would suppose that those IDs should be as constant over time as possible. Plus: they must be unique, at least per page. Having multiple instances of a Wicket component of the same class on one page should then result in different IDs, which could be a rather non-trivial management task. Has anyone experience with such an ID generating strategy?

Upvotes: 0

Views: 227

Answers (1)

martin-g
martin-g

Reputation: 17503

You might be interested in org.apache.wicket.settings.MarkupSettings#setMarkupIdGenerator().

With this method you can set up your own org.apache.wicket.IMarkupIdGenerator that is used to generate ids for each and every component in the application.

Upvotes: 1

Related Questions