要求:有一個文本「禁用」的按鈕。我希望頁面打開時禁用它。當用戶點擊按鈕時,我希望我的表單域被啓用,同時我希望我的按鈕值被更改爲「啓用」。啓用/禁用表單元素並一次更改按鈕的值?
我有一個如何改變按鈕的值的例子,但我該如何同時啓用/禁用它?
<h:form>
Please press the Button it.
<h:commandButton id="cb1" value="#{ActionBean.buttonText}"
immediate="true" actionListener="#{ActionBean.processMyAction}" />
</h:form>
我bean類看起來是這樣的:
/* Action listener method */
public void processMyAction(ActionEvent event) {
disable = !disable;
System.out.println("disable: " + disable);
if (buttonText.equals("Disable")) {
buttonText = "Enable";
System.out.println("buttonText: " + buttonText);
} else {
buttonText = "Disable";
System.out.println("buttonText: " + buttonText);
}
你的要求不明確。你想要一個按鈕來禁用文本,並禁用該按鈕? – Adarsh
@Adarsh我想我在編輯中搞砸了。思考它的意思是說:「我希望它在頁面打開時說'禁用'」,即用戶單擊該按鈕,然後將其禁用並將其值更改爲「啓用」(至少這是唯一的方法合理)。 – mabi
@mabi在這種情況下,在顯示啓用按鈕後將不再有任何用途,因爲按鈕本身將被禁用。這並沒有真正證實他向我們提供的代碼。 – Adarsh