看起来我应该能够在半小时内搜索网页,但是因为我不能:
有效JSF ID的规则是什么?
我读了一个乱码的电子邮件,暗示有限制-
和_
,但我得到IllegalArgumentExceptions,我认为这是由于ID.
编辑
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)
Run Code Online (Sandbox Code Playgroud)
Bal*_*usC 18
它必须是一个有效的CSS标识符(ident
这里),不应该有重复.
在CSS中,标识符(包括选择器中的元素名称,类和ID )只能包含字符
[a-zA-Z0-9]
和ISO 10646字符U+00A1
及更高字符,以及连字符(-
)和下划线(_
); 它们不能以数字开头,也不能以数字后跟连字符开头.标识符还可以包含转义字符和任何ISO 10646字符作为数字代码(请参阅下一项).例如,标识符"B&W?"
可以写为"B\&W\?"
或"B\26 W\3F"
.
更新:对于您感兴趣的情况,这里是验证器的源代码,由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);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然而,它比CSS规则更严格一些.它们也不能以连字符开头.
归档时间: |
|
查看次数: |
6507 次 |
最近记录: |