简体   繁体   中英

Passing JQuery object to Java method using DWR

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM