I think Daniel suggest that Wicket doesn't make /all/ id's unique, only
those that are owned by it by having a component attached to it. And even
then, when you explicitly setMarkupId() you are yourself responsible for
ensuring it is unique.
BarPanel.html:
<wicket:panel>
<h1 id="bar"></h1>
</wicket:panel>
BarPage.html:
<div wicket:id="panel1"></div>
<div wicket:id="panel2"></div>
BarPagel.java:
add(new BarPanel("panel1"));
add(new BarPanel("panel2"));
This would result in two h1 tags with the same HTML id. Wicket doesn't
modify the id magically.
Wicket (from what i know) doesn't support Daniel's usecase out of the box,
but Wicket does have the ability to act on tags if you make such affordance
yourself.
I suppose
<div wicket:aria-label="sect1">
<section wicket:aria-id="sect1">
Could be similarly implemented as the wicket:for attribute.
See AutoLabelTagHandler and AutoLabelTagResolver for more information.
Martijn
On Thu, Jun 30, 2022 at 10:41 PM Martin Grigorov <[email protected]>
wrote:
> On Thu, Jun 30, 2022, 13:50 Daniel Radünz <[email protected]> wrote:
>
> > Thank you kindly both for your suggestions.
> >
> > @Martin Terra
> > I'm not sure I quite undstand what you mean. My hope was that I don't
> have
> > to add any of the involved components to the Java code of every single
> > panel. The example I've given is just one of many. We have many different
> > constellation with completly different html fragments but each of them
> has
> > the same problem, that somewhere in there the html ID of one html tag has
> > to be put into the html attribute of another html tag.
> >
> > @Martin Grigorov
> > The problem I'm having with doing it on the client with javascript or
> with
> > the IResponseFilter is that by that time I can only work on the fully
> > assembled html. If a Wicket page includes the same panel multiple times
> > though, I would already have the same html ID and the
>
>
> Wrong!
> Wicket makes sure that all ids in the page are unique.
>
> With jQuery / JSoup you could query all <section> elements which have a
> child of type <div> with "id" attribute. Iterate over them and add the aria
> attribute.
>
> same reference to it multiple times in the final html without a (bullet
> > proof) way to figure out which two elements ultimatively belong together.
> >
> > That's why I was hoping there would be a way to do this on a panel level,
> > maybe with a custom attribute. Something like
> > <section wicket:aria-labelledby="sectionheader">
> > <h1 wicket:auto-id="sectionheader">
> > </section>
> >
> > If I'd then have a page which has the same panel twice in it, Wicket
> would
> > take care of assinging unique IDs and also putting these generated unique
> > IDs in the corresponding attributes that reference them, resulting in
> > something like this:
> > <section aria-labelledby="sectionheader1">
> > <h1 id="sectionheader1">
> > </section>
> > <section aria-labelledby="sectionheader2">
> > <h1 id="sectionheader2">
> > </section>
> >
> > If there is something like the IResponseFilter but on a per component
> base
> > which would allow me to inspect and modify only the html fragment of a
> > component/panel it might work.
> >
> > Kind regards,
> > Daniel
> >
> >
> > Gesendet: Mittwoch, 29. Juni 2022 um 15:40 Uhr
> > Von: "Martin Grigorov" <[email protected]>
> > An: [email protected]
> > Betreff: Re: Automatically insert generated html IDs in other places in
> > html file
> > Hi,
> >
> > The easiest way I could imagine is with a short jQuery function that is
> > called on domready.
> >
> > If you need to do it on the server side then maybe with IResponseFilter.
> >
> > On Wed, Jun 29, 2022, 12:38 Daniel Radünz <[email protected]> wrote:
> >
> > > Hello everybody,
> > >
> > > I'm wondering if there is a way in Wicket to generate unique html IDs
> and
> > > to then add them in other places in the html, without having to write
> any
> > > boiler plate code in each panel that I have.
> > >
> > > For example in the following panel I need the ID of the h1 tag to be
> put
> > > into the aria-labelledby attribute in the section tag.
> > > <wicket:panel>
> > > <section class="card" aria-labelledby="sectionheader">
> > > <div class="card-header"><h1 id="sectionheader">Lorem
> > > ipsum dolor sit amet</h1></div>
> > > <div class="card-content">Content ...</div>
> > > </section>
> > > </wicket:panel>
> > >
> > > Hardwiring it like in this example of course won't work if I use the
> same
> > > panel class multiple times within a page due to duplicate html IDs.
> > >
> > > While I know I could add WebMarkupContainers for the section and the h1
> > to
> > > my Java code and manually wire them together with an AttributeModifier
> in
> > > Wicket, I woud prefer to have some application wide code which
> recognizes
> > > this constellation in the html file and automatically generates and
> > inserts
> > > the IDs.
> > >
> > > Maybe somebody can push me in the right direction, how I could
> accomplish
> > > this with Wicket, if it's possible at all.
> > >
> > > Kind regards,
> > > Daniel
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [email protected]
> > > For additional commands, e-mail: [email protected]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>
--
Become a Wicket expert, learn from the best: http://wicketinaction.com