Skip to content

Standard HTML components: first-class HTML5 attributes and a common attribute model #2290

Open
0 of 1 issue completed

Description

@pizzi80

Proposal: first-class HTML5 attributes and shared HTML attribute interfaces for the standard HTML components

Summary

The standard HTML components (HtmlInputText, HtmlInputSecret, HtmlInputTextarea, HtmlSelectOneMenu, …) still expose the attribute set of HTML 4. Common HTML5 attributes such as placeholder are only reachable through pass-through attributes. The generated Html* classes also share no common type, so anyone extending them must duplicate the same logic in every component.

This issue proposes, in two independent parts:

  1. Add the missing HTML5 attributes as real component attributes (small, backward compatible).
  2. Introduce interfaces for groups of HTML attributes, modelled on the HTML spec, and have the generated Html* classes implement them (binary compatible).

It also outlines a possible follow-up: opt-in propagation of Faces validation to native HTML validation (nativeValidation).

Background: how we got here

  • 2004 (JSF 1.0). Behaviour (UIInput: conversion, validation, state) was deliberately separated from presentation, so the same component could have several render kits (HTML, WML, XUL…). The Html* classes are generated from a descriptor, one per tag, only to provide typed getters for the HTML attributes of that tag. Java had no default methods, so duplicating those getters in each generated class was the obvious choice.
  • 2013 (JSF 2.2). HTML5 had become mainstream. Instead of extending the attribute lists (placeholder, autocomplete, pattern, min/max, inputmode…), pass-through attributes (xmlns:pt, f:passThroughAttribute) were introduced as a generic escape hatch.
  • 2026. Alternative render kits were never adopted in practice, so the abstraction cost is paid by everyone while the benefit goes to almost no one. Meanwhile:
    • placeholder is used on nearly every form, yet still requires a special namespace: pt:placeholder="#{msg.email}";
    • the generated classes duplicate styleClass, disabled, readonly, onkeypress… and share no common type. A component library adding behaviour common to "all text inputs" (CSS classes, extra attributes) must implement it once per class: HtmlInputText and HtmlInputSecret are siblings under UIInput, and a common abstract base class would lose every generated property;
    • libraries work around this in their own ways: PrimeFaces keeps its own component hierarchy and shares logic in renderer base classes (InputRenderer); others extend each Html* class separately.

Proposal

Part 1: missing HTML5 attributes as real attributes

Add to the relevant components and to the standard HTML render kit attribute lists, with full EL support and documentation in the VDLDoc:

Attribute Components
placeholder h:inputText, h:inputSecret, h:inputTextarea
autocomplete h:inputText, h:inputSecret, h:inputTextarea, h:selectOneMenu, h:form
minlength, pattern, inputmode h:inputText, h:inputSecret, h:inputTextarea (where applicable)
autofocus form controls

Pass-through attributes keep working, and an explicit pt: value keeps precedence, so existing views are unaffected.

Part 2: interfaces for groups of HTML attributes

Modelled on the attribute categories of the HTML spec, for example:

public interface HtmlGlobalAttributes   { String getStyleClass(); String getStyle(); String getTitle(); String getLang(); String getDir(); /* tabindex, accesskey, … */ }
public interface HtmlEventAttributes    { String getOnclick(); String getOnkeypress(); /* … */ }
public interface HtmlFormControl        extends HtmlGlobalAttributes, HtmlEventAttributes { boolean isDisabled(); boolean isReadonly(); String getAutocomplete(); }
public interface HtmlTextControl        extends HtmlFormControl { String getPlaceholder(); int getMaxlength(); int getMinlength(); String getPattern(); }
  • HtmlInputText, HtmlInputSecret and HtmlInputTextarea implement HtmlTextControl; HtmlSelectOneMenu implements HtmlFormControl.
  • The classes stay generated and keep their current getters and setters. Adding implements to an existing class is source and binary compatible.
  • Renderers may read attributes by group instead of from fixed per-tag lists.

Benefits

  • Views: placeholder="#{msg.email}" instead of pt:placeholder, with the same documentation, EL and tooling (autocompletion) as every other attribute.
  • Component libraries: one common type to write shared logic against (CSS state classes, extra attributes), instead of one copy per Html* class.
  • Spec: the attribute model follows the HTML spec instead of a frozen HTML 4 list, and future attributes are added per group rather than tag by tag.
  • Compatibility: no breaking change; pass-through attributes remain for free-form cases (data-*, aria-*, attributes not yet standardized).

Possible follow-up: opt-in native HTML validation (nativeValidation)

The Faces required attribute must keep its current meaning (server-side validation, the only authoritative one). A separate opt-in switch would propagate what Faces already knows about a field to native HTML validation, giving immediate client-side feedback:

  • Switch: a per-component attribute, e.g. nativeValidation="true|false", with an application-wide default from a context parameter, e.g. jakarta.faces.NATIVE_VALIDATION (default false).
  • Mapping:
    • required → required;
    • f:validateLength → minlength and maxlength;
    • f:validateRegex → pattern;
    • f:validateLongRange / f:validateDoubleRange on numeric inputs → min and max;
    • later, the Bean Validation constraints already read for server-side validation (@NotNull, @Size, @Pattern, @Min/@Max).
  • Ajax (essential): native validation only runs on form submit, and faces.ajax.request does not submit the form. With nativeValidation enabled, faces.js should call reportValidity() on the elements in execute before sending, and cancel the request when any of them is invalid. Otherwise native constraints would only change :invalid styling in the most common case.

Open point: the name clash between the HTML required attribute and the Faces required attribute is exactly why native validation should stay a separate, explicit switch rather than an implicit side effect.

Notes

We are implementing equivalent behaviour in our own component library on top of Mojarra (a shared mixin interface for placeholder, CSS state classes and, later, nativeValidation). We can share it as a prototype if useful.

Written with the help of Claude Opus 5.5

Activity

  1. BalusC commented on Nov 20, 2026

    @BalusC
    Member

    Thank you for the detailed proposal. It contains several independent parts with very different cost and risk, so I suggest we keep this issue as an umbrella and track each part as a separate sub-issue. Some of it is already done in 5.0.

    Part 1: missing HTML5 attributes

    • placeholder was added to h:inputText and h:inputTextarea in 5.0 via Add placeholder attribute to h:inputText and h:inputTextarea #2025. It was still missing on h:inputSecret. That is now fixed via Add placeholder attribute to h:inputSecret #2291 (API) and Render placeholder attribute on h:inputSecret eclipse-ee4j/mojarra#6192 (Mojarra).
    • autocomplete is tracked by autocomplete attribute missing on form, input and select* components #542, which becomes a sub-issue. Two things are wrong with the current state. First, it exists only on h:inputText and h:inputSecret, and the spec says to render it only when the value is off. Modern autofill values such as username, current-password, new-password and one-time-code are therefore dropped. Second, it is missing on h:inputTextarea, h:selectOneMenu, h:selectManyMenu, h:selectOneListbox, h:selectManyListbox and h:form. A possible plan for 5.0 is to add it to those components and render any value as-is, if @tandraschko agrees. h:selectBooleanCheckbox, h:selectManyCheckbox and h:selectOneRadio do not get it, because HTML does not apply autocomplete to checkboxes and radio buttons.
    • minlength and inputmode are harmless additions. They can go in one sub-issue.
    • pattern I would rather not add as a first-class attribute. Users will expect it to behave like f:validateRegex, but HTML compiles it as a JavaScript regular expression with the v flag, while Faces uses java.util.regex. The two syntaxes differ, so the same expression can accept different input on client and server. This is the same problem as in your nativeValidation follow-up, so it belongs there.
    • autofocus is allowed on only one element per page (outside dialogs and popovers), so a first-class attribute on every form control adds little over pt:autofocus.

    Part 2: attribute group interfaces

    One correction: the Html* classes are no longer generated. Mojarra removed the code generation in 2018 (eclipse-ee4j/mojarra#4438), and since #1856 the classes are maintained as plain source files in this repository. That actually makes adding interfaces easier.

    The idea itself needs a separate discussion. Every getter on such an interface becomes permanent API, and the attribute categories of the HTML spec do not map one-to-one onto the Faces names (styleClass versus class) and types (int maxlength, String tabindex). Rendering is an implementation concern: Mojarra reads the attributes by name from its own attribute list per component, so a typed interface would not change much there. There is a precedent though: HtmlEvents, introduced in 5.0 via #1507, already models the event tables of the HTML spec as enums, so an attribute counterpart is not unthinkable. Could you open a separate issue for it, ideally with your library's mixin as a concrete example of what it would simplify?

    Follow-up: nativeValidation

    This is the largest part: a new context parameter, changes in faces.js (reportValidity() before an ajax request) and a mapping from validators and Bean Validation constraints to HTML attributes. It deserves its own issue too. The regex syntax difference mentioned above must be solved there, for f:validateRegex as well as @Pattern.

    I will link #542 here as a sub-issue and create one for minlength and inputmode.

    🤖 Generated with Claude Opus 5.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions