Question

I want to pass JQuery object var $this = $(this); to Java method using DWR, I'm doing something like that:

Javascript Method

function handlePieces($square) {
 $square.data('jumped').remove();
 if(player == 1){

        var user = $("#secondPlayer").val();
        DwrUtils.removeJumped(user, $square);
 }else if(player == 2){
        var user = $("#firstPlayer").val();
        DwrUtils.removeJumped(user, $square);
 }
}

My Java Method in DwrUtils Class

@RemoteMethod
public void removeJumped(String user, String square){
    UserLoginScriptSessionFilter filter = new UserLoginScriptSessionFilter(
            user);
    ScriptMethodInvoker invoker = new ScriptMethodInvoker("removeJumped",square);
    Browser.withAllSessionsFiltered(filter, invoker);

}

I have even tried to use Object square instead of String square in method parameters but it still doesn't work.

Should I convert it somehow to Json format or how can I do it ? I'm new to DWR so I don't know exactly how to solve it.

Was it helpful?

Solution

Either square should be a string or a json object for DWR to work.

So convert $square into json object and in the Remote method expect Square square

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top