这个问题在这里已经有了答案:
How can I create toggle buttons in JSF?
(1 个回答)
6年前关闭。
场景如下所示:
屏幕上有两个按钮,比如 button1 和 button2。在页面加载时,button2 被禁用。当用户单击 button1 时,将启用 button2。我使用 javascript window.onload 事件和 button1 上的 onclick 事件实现了这个功能。我的问题是,当用户单击 button1 时,它会触发页面重新加载。话虽如此,在重新加载页面后,由于 onload 事件,button2 被禁用。
有没有另一种方法来实现这个功能?
顺便说一句,我正在使用primefaces。
最佳答案
primeface 页面是这样的,
<p:commandButton update="panel1" actionListener="#{bean.button1}" value="button1" disabled="#{bean.disable}">
<f:setPropertyActionListener value="#{false}" target="#{bean.disable}"/>
</p:commandButton>
<p:commandButton update="panel2" actionListener="#{bean.button2}" value="button1" disabled="#{!(bean.disable)}">
<f:setPropertyActionListener value="#{true}" target="#{bean.disable}"/>
</p:commandButton>
管理 Bean:
public class Bean {
private boolean disable;
// default constructor
public Bean(){
this.disable= false;
}
public boolean isDisable() {
return disable;
}
public void setDisable(boolean disable) {
this.disable = disable;
}
}
关于jsf - 如何启用/禁用 JSF 命令按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9080005/