| |
| Tag attribute _id_ plays a crucial role in web development as it allows JavaScript to identify a DOM element. That's why class _Component_ provides two dedicated methods to set this attribute. With method _setOutputMarkupId(boolean output)_ we can decide if the _id_ attribute will be rendered or not in the final markup (by default is not rendered). The value of this attribute will be automatically generated by Wicket and it will be unique for the entire page. |
| If we need to specify this value by hand, we can use method _setMarkupId(String id)_. The value of the id can be retrieved with method _getMarkupId()_. |
| |
| Wicket generates markup ids using an instance of interface _org.apache.wicket.IMarkupIdGenerator_. The default implementation is _org.apache.wicket.DefaultMarkupIdGenerator_ and it uses a session-scoped counter to generate the final id. A different generator can be set with the markup settings class _org.apache.wicket.settings.MarkupSettings_ available in the application class: |
| |
| [source,java] |
| ---- |
| @Override |
| public void init() |
| { |
| super.init(); |
| getMarkupSettings().setMarkupIdGenerator(myGenerator); |
| } |
| ---- |
| |