Repository navigation
Description
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:
- Add the missing HTML5 attributes as real component attributes (small, backward compatible).
- 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…). TheHtml*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:
placeholderis 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:HtmlInputTextandHtmlInputSecretare siblings underUIInput, 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 eachHtml*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,HtmlInputSecretandHtmlInputTextareaimplementHtmlTextControl;HtmlSelectOneMenuimplementsHtmlFormControl.- The classes stay generated and keep their current getters and setters. Adding
implementsto 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 ofpt: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(defaultfalse). - Mapping:
required→required;f:validateLength→minlengthandmaxlength;f:validateRegex→pattern;f:validateLongRange/f:validateDoubleRangeon numeric inputs →minandmax;- 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.requestdoes not submit the form. WithnativeValidationenabled,faces.jsshould callreportValidity()on the elements inexecutebefore sending, and cancel the request when any of them is invalid. Otherwise native constraints would only change:invalidstyling 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
BalusC commentedon Nov 20, 2026
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
placeholderwas added toh:inputTextandh:inputTextareain 5.0 via Add placeholder attribute to h:inputText and h:inputTextarea #2025. It was still missing onh: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).autocompleteis 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 onh:inputTextandh:inputSecret, and the spec says to render it only when the value isoff. Modern autofill values such asusername,current-password,new-passwordandone-time-codeare therefore dropped. Second, it is missing onh:inputTextarea,h:selectOneMenu,h:selectManyMenu,h:selectOneListbox,h:selectManyListboxandh: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:selectManyCheckboxandh:selectOneRadiodo not get it, because HTML does not applyautocompleteto checkboxes and radio buttons.minlengthandinputmodeare harmless additions. They can go in one sub-issue.patternI would rather not add as a first-class attribute. Users will expect it to behave likef:validateRegex, but HTML compiles it as a JavaScript regular expression with thevflag, while Faces usesjava.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 yournativeValidationfollow-up, so it belongs there.autofocusis allowed on only one element per page (outside dialogs and popovers), so a first-class attribute on every form control adds little overpt: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 (
styleClassversusclass) 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:
nativeValidationThis 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, forf:validateRegexas well as@Pattern.I will link #542 here as a sub-issue and create one for
minlengthandinputmode.🤖 Generated with Claude Opus 5.5