0

In my app I need to add string vallues to the file(.property file, if it is important). and user enter this values in gwt GUI. Here is it's important part:

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);
    }

So I need to use Asunccallback to call methods which are in the "server part". here are these methods:

//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";
    }

all interfaces are present. when I run my code And press "submit" button in gui I see that both asynccallback failured(Window.alert, as you can see, shows "null pointer exception" despite of the fact that values which I send to methods are not null). why can it be? can you suggest me something?

UPD here is error which is shown by firebug:

uncaught exception: java.lang.ClassCastException    
function W8(){try{null.a()}catch(a){return a}} 
Nikitin Mikhail
  • 2,983
  • 9
  • 42
  • 67
  • Does the server receive the requests? What about the server log? – home Apr 12 '13 at 12:33
  • Actually, I'm a newby in programming, and can't say this because don't know how. only firebug in firefox shows that the Post has appropriate values and one error, which I can't understand what is. I'll update my post now – Nikitin Mikhail Apr 12 '13 at 12:41

2 Answers2

0

the problem is solved: there were a simple mistake in the code. I've closed brackets at the wrong place:

//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";
    }
Nikitin Mikhail
  • 2,983
  • 9
  • 42
  • 67
0

I recommend that you recompile the GWT code using -style PRETTY and then check that firebug output again; it may give you a better clue, compared to your updated uncaught exception.

Next, I suggest you run it in the eclipse debugger, and set breakpoints in both the client and server code, and then you can inspect the variables and step through the code.

Jamie
  • 1,888
  • 1
  • 18
  • 21