A reversed PatternValidator renders a pattern attribute that rejects the input the validator accepts

Open
#1,886 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@reiern70 is already working on this.

Since Nov 12, 2026.

  • #1890 by @reiern70 — open
  • #1892 by @reiern70 — open
  • #1893 by @reiern70 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
html, java
Domain
frontend

Research direction

The pattern attribute is written in AbstractTextComponent#onComponentTag and HTML5Attributes#onInput, both in wicket-core. Start by reading how those two places iterate over the PatternValidator instances, and add an isReverse() getter to PatternValidator. Done when a reversed validator no longer produces a pattern attribute in the rendered <input>, and the existing tests for HTML5 attributes still pass.

Written by the indexing model from the issue text.

Description

Affects: 11.0.0 and current master, on every text component. 10.x when the HTML5Attributes behavior is added.
Component: wicket-core, AbstractTextComponent, HTML5Attributes, PatternValidator

What happens

A text field with a reversed PatternValidator:

field.add(new PatternValidator("[a-z]+").setReverse(true));

renders:

<input type="text" ... pattern="[a-z]+">

The validator means "input that matches [a-z]+ is invalid". The pattern attribute tells the browser the opposite: input that does not match is invalid. A non-empty value can't pass both checks:

  • 123 is valid on the server, but the browser blocks the submit (patternMismatch, checked in Chrome and Firefox).
  • abc passes the browser, and the server rejects it.

Only an empty value gets through, because neither check applies to it.

Cause

AbstractTextComponent#onComponentTag (and HTML5Attributes#onInput) copies the pattern of every PatternValidator into the pattern attribute and ignores the reverse flag. PatternValidator has no getter for that flag, so the renderers can't see it.

Fix proposed

Render no pattern attribute for a reversed validator, and leave the check to the server. An HTML pattern can't express "must not match" reliably for an arbitrary Java pattern. This needs a public getter, PatternValidator#isReverse().

Workaround

Remove the attribute with a behavior added after the validator:

field.add(new Behavior() {
    @Override
    public void onComponentTag(Component component, ComponentTag tag) {
        tag.remove("pattern");
    }
});

Found while fixing #1884.

Dominant language
Java
Stars
800
Forks
437
Avg merge
21h 36m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/wicket

All issues in apache/wicket

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.