It seems like I should be able to find this with a half hour of searching the webs, but since I cannot:
What are the rules for valid JSF ids?
I read a garbled e-mail message that suggested there were limitations on -
and _
, but I'm getting IllegalArgumentExceptions and I think it's due to the ids.
EDIT
java.lang.IllegalArgumentException: 6a945017207d46fd82b3d3bb7d2795f1
at javax.faces.component.UIComponentBase.validateId(UIComponentBase.java:549)
at javax.faces.component.UIComponentBase.setId(UIComponentBase.java:351)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:151)
It has to be a valid CSS identifier (the ident
here) and there should be no duplicates.
In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters
[a-zA-Z0-9]
and ISO 10646 charactersU+00A1
and higher, plus the hyphen (-
) and the underscore (_
); they cannot start with a digit, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier"B&W?"
may be written as"B\&W\?"
or"B\26 W\3F"
.
Update: for the case you're interested, here's the source code of the validator as provided by UIComponentBase#validateId()
:
private static void validateId(String id) {
if (id == null) {
return;
}
int n = id.length();
if (n < 1) {
throw new IllegalArgumentException("Empty id attribute is not allowed");
}
for (int i = 0; i < n; i++) {
char c = id.charAt(i);
if (i == 0) {
if (!Character.isLetter(c) && (c != '_')) {
throw new IllegalArgumentException(id);
}
} else {
if (!Character.isLetter(c) &&
!Character.isDigit(c) &&
(c != '-') && (c != '_')) {
throw new IllegalArgumentException(id);
}
}
}
}
It's however a little more strict than the CSS rules. They cannot start with a hyphen as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With