• Fat Cats Boardgame
  • Wicket UI Library
  • About Me

Java and Wicket web development thoughts, tutorials, and tips

roman@coderdreams.com
Coder DreamsCoder Dreams
  • Fat Cats Boardgame
  • Wicket UI Library
  • About Me

Tracking down a bug in production Wicket application

June 20, 2020 Posted by Roman Sery debugging, wicket 1 Comment

This past week I spent a lot of time investigating problems a user was having with a production Wicket application. The problems are difficult to accurately describe and were varied:

  • Various ajax components would sometimes not invoke their behaviors.
  • Clicking buttons would sometimes invoke an unexpected behavior associated with a completely different button.
  • Sometimes clicking a save button to submit a form would not work and would reload the page with a behavior callback URL instead of the original URL.

The user lives in a rural area and has a very slow internet connection and connects through a VPN. We thought about the possibility of network instability, packet loss, or VPN interference. But it was none of those things.

If you want the short answer, DefaultMarkupIdGenerator was generating duplicate id’s in some cases because it tries to optimize the length of the ids in deployment mode. Read on for more!

Background

So you have a better picture of the scenario, it’s necessary to describe the particular interface and action that would lead to the problems. We have a search page with filters and a table of results. Clicking the search button would apply the filters and update the results. We also have an autocomplete dropdown for searching by keyword. Upon selecting a record in the dropdown, you would be redirected to the record page.

The user would come to the search page, type a keyword, and make a selection. While the redirect was happening, they would also out of habit click the search button. It would load the new page after a few seconds, and the above-mentioned problems would start.

Cause

Wicket auto-generates DOM ids for all components added to the page so that we don’t have to worry about giving each component a unique ID. In deployment mode, DefaultMarkupIdGenerator tries to optimize the length of these ids by using a constant prefix “id” and appending a session-based sequence number.

In rare cases such as described above, when a behavior is invoked that changes the state of the page which requires more generation of ids while a redirect to a different page is happening, which itself is generating ids, some type of conflict causes duplicate ids to be generated.

With duplicate ID’s, the Wicket callbacks that are registered would not work. Sometimes it would invoke the wrong callback, or not invoke at all.

Solution

The solution I implemented was simply to modify the id generation to use the component ID and the component’s parent ID:

String markupIdPostfix = Integer.toHexString(generatedMarkupId).toLowerCase(Locale.ROOT);

String markupIdPrefix = component.getId();
if(component.getParent() != null) {
    markupIdPrefix += component.getParent().getId();
}
String markupId = markupIdPrefix + markupIdPostfix;

The only downside I can see is the slightly increased page size due to the longer ids. I wasn’t able to reproduce this locally until I switched to deployment mode. In development mode, DefaultMarkupIdGenerator uses the component’s ID which makes duplicates much less likely. I went one step further to include the component’s parent ID.

Your chances of encountering this increases as the size of your page increases. If you have a small page with 100 components, it will be very unlikely. However the pages in our application regularly have 2000+ components.

Suggestion

My suggestion would be to change the behavior of DefaultMarkupIdGenerator to use a safer generation method by default and leave it up to the developer if they want to optimize the length of the ids to try to save a bit on their page size.

1 Comment
Share
2

About Roman Sery

I've been a software developer for over 10 years and still loving Java!

You also might be interested in

Using MySQL JSON columns to simplify your data storage: Part 2

Dec 6, 2019

In part 2, we get into the nitty gritty details of how to implement the hybrid approach.

Initializing your Wicket components using the builder pattern

Mar 18, 2020

How to use the builder pattern to initialize your custom Wicket components and the advantages of doing it.

autocomplete

Wicket autocomplete components with remote data

Jan 5, 2020

Autocomplete or type-ahead fields are used when the large number of options makes it infeasible to use dropdowns containing all the possible options. Let's learn how to implement them in Wicket.

Categories

  • aws
  • customization
  • database
  • debugging
  • enum
  • java
  • models
  • performance
  • projects
  • react
  • software design
  • Spring
  • tool
  • Uncategorized
  • wicket

Recent Posts

  • Rent Day
  • Self-contained Wicket Fragments
  • Pros and cons of unit testing
  • Themeable React Monopoly board
  • Please dont use client-specific release branches

Recent Comments

  • TCI Express Thanks for sharing such insightful information. TCI Express truly stands out as the best air logistics company, offering fast, secure, and efficient air express and cold chain transportation services....

    Tracking down a bug in production Wicket application ·  March 25, 2025

  • Tom Error: A zip file cannot include itself Can you please correct the plugin part so it doesn't use the same folder as input?

    Deploying Spring Boot app to AWS Beanstalk with Nginx customization ·  September 3, 2021

  • Golfman: Reality always wins I've used both Wicket and front-end JS frameworks and, having worked extensively on both, I can tell you that "Speed of development" is definitely NOT with the JS frameworks. You basically end up...

    Five reasons you should use Apache Wicket ·  August 29, 2021

  • Kiriller Sorry can not agree with you, wicket might be a well built technical framework. But the advantages of using a front-end framework like react.js and vue.js can not be beaten by Wicket nowadays. - Speed...

    Five reasons you should use Apache Wicket ·  August 23, 2021

  • Bernd Lauert Sorry but i have to refute your claims with the following arguments: 1. the Wicket community may be small but it is also very responsive, you usually get a helpful answer from the core devs on the...

    Five reasons you should use Apache Wicket ·  July 1, 2021

Archives

  • May 2021
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019

Contact Me

Send Message
Prev Next