Java 在支持bean中获取jsf组件id

Java 在支持bean中获取jsf组件id,java,jsf,jsf-2,richfaces,Java,Jsf,Jsf 2,Richfaces,我有两个jsf组件,如下所示: <a4j:commandButton id="cmdtop" disabled="#{ViewDocument.locked or !(documentAttachmentBean.canEditAttachment )}" action="#{documentAttachmentBean.onCmdIncreaseAttachmentCodeClick}"

我有两个jsf组件,如下所示:

 <a4j:commandButton id="cmdtop"

                   disabled="#{ViewDocument.locked or !(documentAttachmentBean.canEditAttachment )}"
                   action="#{documentAttachmentBean.onCmdIncreaseAttachmentCodeClick}"

                   ...


</a4j:commandButton>

<a4j:commandButton id="cmddown"
                   disabled="#{ViewDocument.locked or !(documentAttachmentBean.canEditAttachment )}"
                   action="#{documentAttachmentBean.onCmdDecreaseAttachmentCodeClick}">    
    ...                     

</a4j:commandButton>
}


如何找到canEditAttachment()是由谁调用的?

JSF中有一些全局变量<代码>组件就是其中之一。您可以使用
component
变量访问当前正在渲染的组件

xhtml

<h:commandButton id="cmdtop"
                 disabled="#{myBackingBean.canEditAttachment(component.id)}"
                 value="Button 1"/>

<h:commandButton id="cmddown"
                 disabled="#{myBackingBean.canEditAttachment(component.id)}"
                 value="Button 2"/>

我相信这只适用于JSF2.0。JSF2.0添加了隐式变量,使解析组件更容易

disabled=“#{myBackingBean.canEditAttachment(component.id)}”


如果您使用的是使用低于2.0的JSF的过时遗留代码,那么这将不起作用。

谢谢!它起作用了!但是你能说其他全局变量吗?它们被命名为隐式对象。网站上有一个列表。
<h:commandButton id="cmdtop"
                 disabled="#{myBackingBean.canEditAttachment(component.id)}"
                 value="Button 1"/>

<h:commandButton id="cmddown"
                 disabled="#{myBackingBean.canEditAttachment(component.id)}"
                 value="Button 2"/>