java setenabled_java – Button:setEnabled(false)无法正常工作?

我想我只是做了一些愚蠢的事情,但我无法想出这个.

我正在使用GWT,并且我有一个提交按钮,其中submit通过REST API将一些信息发送到远程服务器.问题是,您可以在操作完成时单击提交多次,并创建多个帖子.

我试过添加

sendButton.setEnabled(false);

到点击处理程序,但它似乎没有工作.该按钮保持启用状态,我仍然可以根据需要多次点击该按钮,从而产生多个帖子.有人能看出我做错了吗?完整的代码如下.

public class HelpDeskTest implements EntryPoint {

private final HelpDeskTestServiceAsync helpDeskTest= GWT.create (HelpDeskTestService.class);

final Button sendButton = new Button("Submit");

final TextBox nameField = new TextBox();

final Label errorLabel = new Label();

final TextBox subjectField = new TextBox();

final TextArea descriptionField= new TextArea();

/**

* This is the entry point method.

*/

public void onModuleLoad() {

// We can add style names to widgets

//sendButton.addStyleName("sendButton");

// Add the nameField and sendButton to the RootPanel

// Use RootPanel.get() to get the entire body element

RootPanel.get("nameFieldContainer").add(nameField);

RootPanel.get("subjectFieldContainer").add(subjectField);

RootPanel.get("descriptionFieldContainer").add(descriptionField);

RootPanel.get("sendButtonContainer").add(sendButton);

RootPanel.get("errorLabelContainer").add(errorLabel);

//set name field text

nameField.setText("GWT User");

// Focus the cursor on the name field when the app loads

subjectField.setFocus(true);

subjectField.selectAll();

//set widths and heights

descriptionField.setWidth("100%");

descriptionField.setHeight("200px");

nameField.setWidth("100%");

subjectField.setWidth("100%");

//click handler

sendButton.addClickHandler(new ClickHandler() {

@Override

public void onClick(ClickEvent event) {

sendButton.setEnabled(false);

String uName = nameField.getText();

String subject = subjectField.getText();

String desc = descriptionField.getText();

String newURLp1 = "http://xxx.xx.xx/sdpapi/request?" +

"OPERATION_NAME=ADD_REQUEST&TECHNICIAN_KEY=D4xxxxxxxB6" +

"&INPUT_DATA=<?xml version=";

String urlp2 = "%221.0%22";

String urlp3 = " encoding=";

String urlp4 = "%22utf-8%22";

String urlp5 = "?>" + uName + "" + subject +

"" + desc + "";

String encUrl = URL.encode(newURLp1) + urlp2 + URL.encode(urlp3) + urlp4 + URL.encode(urlp5);

System.out.println(encUrl);

helpDeskTest.postToRemoteServer(encUrl,

new AsyncCallback() {

@Override

public void onFailure(Throwable caught) {

Window.alert("Failure getting XML through proxy");

}

@Override

public void onSuccess(String result) {

processXML(result);

}

});

sendButton.setEnabled(true);

}

});

}

public void processXML(final String xml) {

try {

Document doc = XMLParser.parse(xml);

// get the status using Node's getNodeValue() function - this will determine success or failure.

String status = doc.getElementsByTagName("status").item(0).getFirstChild().getNodeValue();

//if success:

if (status.equals("Success")) {

String statCode = doc.getElementsByTagName("statuscode").item(0).getFirstChild().getNodeValue();

String msg = doc.getElementsByTagName("message").item(0).getFirstChild().getNodeValue();

String woid = doc.getElementsByTagName("workorderid").item(0).getFirstChild().getNodeValue();

System.out.println("Result from HelpDesk:");

System.out.println("Status Code: " + statCode);

System.out.println("Status: " + status);

System.out.println(msg);

System.out.println(msg + ". Ticket Number is: " + woid);

errorLabel.setText(msg + ". Ticket Number is: " + woid);

} else if (status.equals("Failed")){

//get message

String failmsg = doc.getElementsByTagName("message").item(0).getFirstChild().getNodeValue();

errorLabel.setText(failmsg);

}

}

catch ( Exception e ) {

e.printStackTrace();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值