我有两个像这样的 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>
在我的支持 bean 中,使用 canEditAttachment() 方法,我想检查它是否已被 cmdtop 或 cmddown 调用? 像这样的事情:
public boolean getCanEditAttachment()
{
if (somecode.getElementId.equals"cmdtop")
//do something
return true ;
else if (somecode.getElementId.equals"cmddown")
//do something else
return false ;
}
如何找到 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"/>
java
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class MyBackingBean {
public boolean canEditAttachment(String componentId) {
if ("cmdtop".equalsIgnoreCase(componentId))
return true;
else if ("cmddown".equalsIgnoreCase(componentId))
return false;
return true;
}
}
关于java - 获取支持 bean 中的 jsf 组件 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26956546/