gpt4 book ai didi

jsf - JSF id 的规则是什么?

转载 作者:行者123 更新时间:2023-12-02 19:21:52 24 4
gpt4 key购买 nike

看起来我应该能够在网上搜索半小时找到这个,但因为我不能:

有效 JSF ID 的规则是什么?

我读到一封乱码电子邮件,表明 -_ 存在限制,但我收到了 IllegalArgumentExceptions,我认为这是由于 ids 造成的。

编辑

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)

最佳答案

它必须是有效的 CSS identifier (ident here)并且不应有重复项。

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+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".

另请参阅:

<小时/>

更新:对于您感兴趣的情况,以下是 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);
}
}
}
}

但是它比 CSS 规则更严格一些。它们也不能以连字符开头。

关于jsf - JSF id 的规则是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5972433/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com