在我的应用程序中,我需要将字符串值添加到文件(.property文件,如果它很重要)。并且用户在gwt GUI中输入这个值。下面是它的重要组成部分:asynccallback failures
final Button submit = new Button("Submit");
addButton(submit);
submit.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
keyWord.selectAll();
regexp.selectAll();
if (keyWord.getValue() != null){
setKeyWord(customerId, keyWord.getValue());
keyWord.setValue("");
}
if (regexp.getValue() != null){
setRegExp(customerId, regexp.getValue());
regexp.setValue("");
}
}
});
}
private void setKeyWord(final String customerId, final String keyword){
final AsyncCallback<String> callbackItems = new AsyncCallback<String>() {
public void onFailure(final Throwable caught) {
Window.alert("unable to add " + caught.toString());
}
public void onSuccess(final String x) {
Window.alert(x);
}
};
serverManagementSvc.setKeyWords(customerId, keyword, callbackItems);
}
private void setRegExp(final String customerId, final String regexp){
final AsyncCallback<String> calbackItems = new AsyncCallback<String>() {
@Override
public void onFailure(Throwable throwable) {
Window.alert("unable to add " + throwable.toString());
}
@Override
public void onSuccess(String s) {
Window.alert(s);
}
};
serverManagementSvc.setRegExp(customerId, regexp, calbackItems);
}
所以我需要使用Asunccallback调用它们是在“服务器的一部分”的方法。 这里是这些方法:
//adds a new keyword to customers properties
public String setKeyWords(String customer, String word){
try{
PropertiesConfiguration props = new PropertiesConfiguration("/home/mikhail/bzrrep/DLP/DLPServer/src/main/resources/rules.properties");
String newKeyWord = new String(props.getString("users." + customer + ".keywords" + "," + word));
props.setProperty("users." + customer + ".keywords", newKeyWord);
props.save();
}catch (ConfigurationException e){
e.printStackTrace();
}
return "keyword " + word + " added";
}
// adds a new regexp to customer properties
public String setRegExp(String customer, String regexp){
try {
PropertiesConfiguration props = new PropertiesConfiguration("/home/mikhail/bzrrep/DLP/DLPServer/src/main/resources/rules.properties");
String newRegValue = new String(props.getString("users." + customer + ".regexps" + "," + regexp));
props.setProperty("users." + customer + ".regexps", newRegValue);
props.save();
} catch (ConfigurationException e){
e.printStackTrace();
}
return "regexp " + regexp + " added to " + customer + "'s config";
}
所有接口都存在。 当我运行我的代码并按gui中的“提交”按钮我看到,两个asynccallback失败(Window.alert,如你所见,显示“空指针异常”,尽管我发送给方法的值不为null )。为什么会这样?你能告诉我什么吗?
UPD这里是错误,是由萤火虫显示:
uncaught exception: java.lang.ClassCastException
function W8(){try{null.a()}catch(a){return a}}
服务器是否收到请求?服务器日志怎么样? – home
实际上,我是编程中的一名新手,不能说这是因为不知道如何。 firefox中只有firebug表明Post有适当的值和一个错误,我不明白是什么。我现在更新我的帖子 –