Aw: Re: Re: Automatically insert generated html IDs in other places in html file
Thank you again for your input and sorry for the slow responses. Been unexpectedly busy with more urgent problems in my project. Beforehand: If it's still not clear what I'm trying to achieve after this message, I'll happily provide the requested quickstart, though from your responses and my own digging I already get the feeling, that it might just not be possible ... While the idea of Martin Terra with using a generic panel is good, the example that I've given with the h1 in the section is sadly just a simple one to show the general problem. There are many many use cases with aria-* accessibillity attributes where you have to add the id of one element to an attribute of another element. aria-labelledby, aria-owns, aria-controls, aria-describedby, ... just to name a few. With many of those you don't always have the convinient case that these elements encase eachother as they do in my example. They could be encased the other way around or not all and both just be direct children of another parent element. They might not even be in close proxymity, as an element right at the beginning of a panel could reference an element which is at the very end of that panel. So yes, I might be able to write some JS code for this very particular simple example but as soon as the structure changes or in general I have panels with different structures, the JS code would fail or I would at least have to write different JS code for each case. That's why I'd like to do it on the server side where it's reasonable to assume to have unique Wicket IDs in a panel.html file which then get turned into unique html IDs when wicket assembles the full page. Maybe I failed to make clear that of course I am well aware of how to do this the "hard" way with some boiler plate could. I know I could very well have this bit of html: Lorem ipsum and wire everything together with this bit of code: WebMarkupContainer section = new WebMarkupContainer("section"); add(section); WebMarkupContainer sectionheader = new WebMarkupContainer("sectionheader"); sectionheader.setOutputMarkupId(true); section.add(sectionheader); section.add(AttributeModifier.replace("aria-labelledby", sectionheader::getMarkupId)); which would produce something like this with unique IDs Lorem ipsum But I wanted to avoid that. Adding these elements to the Java side has no real benefits in my eyes. If I write this in html Lorem ipsum it's already clear from the html side that the developer wants to wire these components togehter just by having the attributes on the corresponding tags. Adding any (boiler plate-)code on the Java side increases the complexitiy, feels redundant and in the worst case even causes trouble. So the idea was that maybe there is a way to write whatever "global" behaviour/listener/filter etc. to recognise matching pairs id- and aria-*-attributes in a Wicket panel and then generate and insert unique IDs into these places within a panel. I will check out AutoLabelTagHandler and AutoLabelTagResolver again as Martijn suggested. With that said, if it turns out, that it's not possible, I will just have to do it the "old fashioned" way by adding everything on the Java side as well. I just wanted to know ahead of that if somebody has solved this problem in a more elegant way before and I would maybe not have to reinvent the wheel. Thank you for your time and kind regards Daniel Radünz Gesendet: Sonntag, 03. Juli 2022 um 22:36 Uhr Von: "Martin Grigorov" An: users@wicket.apache.org Betreff: Re: Re: Automatically insert generated html IDs in other places in html file On Sat, Jul 2, 2022, 15:18 Martijn Dashorst wrote: > 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: > > > 1. Don't set the ID in HTML 2. Use panel.setOutputMarkupId(true) Voila! > > BarPage.html: > > > > 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 > > > > > Could be similarly implemented as the wicket:for attribute. > See AutoLabelTagHandler and AutoLabelTagResolver for more information. > > Martijn > > -- > Become a Wicket expert, learn from the best: http://wicketinaction.com > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Aw: Re: Automatically insert generated html IDs in other places in html file
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 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 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: 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" An: users@wicket.apache.org 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 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. > > > Lorem > ipsum dolor sit amet > Content ... > > > > 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: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Automatically insert generated html IDs in other places in html file
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. Lorem ipsum dolor sit amet Content ... 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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Problem with MetaData when detaching Component
Thanks for the response! I switched to using the RequestCycle to store the component related data, which solved the specific problem for me. :) Nevertheless I have created a bug reported with a quickstart attached as requested. (WICKET-6877) Regards, Daniel Am 12.04.2021 um 12:24 schrieb Martin Grigorov: Hi, On Mon, Apr 12, 2021 at 12:13 PM Daniel Radünz wrote: It sounds like a bug to me! Please create an issue in JIRA. With a failing test case would be perfect! To work it around you can probably use RequestCycle's MetaData instead. Regards, Martin - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Problem with MetaData when detaching Component
Hello, I am facing a problem with our Wicket 8.10.0 application and I wonder if it's a bug or if I am using the MetaData feature in an unsupported or wrong way. I have a Behavior, which adds a MetaData entry to a component in the Behavior's "onConfigure(Component component)" method and later removes the same MetaData again from the component in the Behaviour's "detach(Component component)" method. (I'll skip explaining what it is used for, but if it's important to understand my use case I'll gladly explain it) Now upon detaching the component with said Behaviour, Wickets NotDetachedModelChecker encountered a not detached model in the component. After debugging the problem for a few hours I discovered the cause: Right before the detach phase starts, the components internal "data" field is an array with the following 4 entries: - [0] the component's Model - [1] the MetaDataEntry belonging to the described Behavior - [2] the Behavior itself - [3] an AttributeModifier with a StringResourceModel When the component's "detach()" method is called by Wicket, it internally calls the static "Behaviors.detach(Component component)" method. This method then iterates through all the entries in the aforementioned "data" array and detaches them, if they are Behaviours. Now when it detaches the Behavior (index 2), the MetaDataEntry (index 1) gets removed as well by our Behavior, shifting every entry in the data array by 1. The next loop iteration for index 3 then doesn't find anything anymore, since the AttributeModifier, which still needed to get detached, is now at index 2 and not 3 anymore, ultimately resulting in the observed error from the NotDetachedModelChecker. To fix the problem for now I set the MetaDataEntry to a known non-null "undefined" value in the Behavior's "detach(Component component)" method and then compare that value again in the Behavior's "onConfigure(Component component)" to treat it as null. Now I wonder, if you would consider this being a bug, if I'm just using it the wrong way or if I should rather save the information in a different way, like for example in a map (Component mapped to value) in the RequestCycle object. Thanks for your help Daniel - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org