jsf条件设置id

jsf条件设置id,jsf,parameters,custom-tag,Jsf,Parameters,Custom Tag,我有一个自定义标记,希望允许设置内部元素的id <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:rich="http://richfaces.org/rich"

我有一个自定义标记,希望允许设置内部元素的id

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j">

<f:subview rendered="#{not empty id}">
    <h:message styleClass="message" id="#{id}" errorClass="message error"
        warnClass="message warn" for="#{element}" />
</f:subview>
<f:subview rendered="#{not id}">
    <h:message styleClass="message" errorClass="message error"
        warnClass="message warn" for="#{element}" />
</f:subview>
</html>
当用户设置一个id时,我如何存档它被使用,而当jsf不使用时,它应该自己生成它

使用
有条件地添加一个
id

<h:message styleClass="message" errorClass="message error" warnClass="message warn" for="#{element}">
    <c:if test="#{not empty id}">
        <f:attribute name="id" value="#{id}" />
    </c:if>
</h:message>

顺便说一下,在自定义标记中使用
而不是
,甚至不使用它,这是非常奇怪的。您确定最终得到的是语法有效的HTML吗?此外,您的第二个
表达式不正确,但这与您收到的特定错误消息无关。

使用的答案给我留下了
UIComponent
类中的
IllegalArgumentException
,它是专门为
id
抛出的:

else if ("id".equals(name) || "parent".equals(name)) {
    throw new IllegalArgumentException();
}
我最终使用了Omnifaces'
o:tagAttribute

else if ("id".equals(name) || "parent".equals(name)) {
    throw new IllegalArgumentException();
}