Home

PropertyKeys

PropertyKeys is a conventional inner enum pattern used in JavaServer Faces (JSF) to enumerate the property names of a custom UIComponent. By declaring an enum named PropertyKeys inside the component class, developers create a fixed set of keys that identify values stored in the component’s state via the StateHelper. This replaces the older practice of using plain string literals as property keys and helps catch typos at compile time through the enum type system.

Usage typically involves defining a small enum with constants that correspond to the component’s properties, for

Benefits of this pattern include improved type safety, easier refactoring, and better IDE support due to enumerated

example:
public
enum
PropertyKeys
{
label,
value,
required
}.
Accessors
then
retrieve
and
store
values
through
the
StateHelper,
such
as:
public
String
getLabel()
{
return
(String)
getStateHelper().eval(PropertyKeys.label,
null);
}
public
void
setLabel(String
label)
{
getStateHelper().put(PropertyKeys.label,
label);
}.
The
StateHelper
is
responsible
for
saving
and
restoring
component
state
across
requests,
making
PropertyKeys
a
way
to
organize
state
keys
in
a
type-safe
manner.
constants.
It
also
reduces
the
risk
of
miskeying
because
property
keys
are
defined
in
one
place
and
referenced
via
the
enum,
rather
than
scattered
string
literals.
While
common
in
JSF
custom
component
development,
the
pattern
is
optional;
some
implementations
still
use
string
keys.
The
key
idea
is
to
provide
a
stable,
refactor-friendly
set
of
keys
that
map
to
the
component’s
stateful
properties.