简体   繁体   中英

How to call java method using javascript in ZK MVVM?

I am using Edraw Office Viewer component to open & edit the file. I want to save my file to my destination point so I am using JavaScript to save the file. But I am stuck at a point. I am showing my code below to save document using JavaScript.

function f_saveDocument(){
    if(document.OA1.IsOpened)           
    {   
    var saveAsFileName = document.getElementById('hdnFileName').value;
    alert(saveAsFileName);
        var fileFormat = saveAsFileName.substring(saveAsFileName.lastIndexOf("."));
        if(fileFormat == '.docx') {
            var toUnLockFile = 'MergeTest'+fileFormat;
            var tempFileLocation = document.OA1.GetTempFilePath(saveAsFileName);
            var tempToUnLockFileLocation = document.OA1.GetTempFilePath(toUnLockFile);
            document.OA1.SaveAs(tempFileLocation,12);
            document.OA1.SaveAs(tempToUnLockFileLocation,12);
            document.OA1.HttpInit();
            document.OA1.HttpAddPostFile(tempFileLocation);
              document.OA1.HttpPost(""); 
            document.OA1.ClearTempFiles();
        } else {
        alert("asdsa");
            document.OA1.HttpInit();
            document.OA1.HttpAddPostOpenedFile(saveAsFileName);
             **zAu.send(new zk.Event(zk.Widget.$('$btnSave'), "saveFile", {'' : {'data' : {'nodeId': ''}}}, {toServer:true}));** 
         alert("moved");
        }

    } 

In case of JSP page I can put my JSP URL in HttpPost but in case of ZK how to move from this JavaScript to Java method. So to overcome this problem I am using Widget to call saveFile() method which is in my viewmodel class. But zAu.send is not working fine. Can any body tell other solution to call my Java method from JavaScript in ZK MVVM.

Your code is simply wrong

zAu.send(new zk.Event(zk.Widget.$('$btnSave'), "onSaveFile", {'' : {'data' : {'nodeId': ''}}}, {toServer:true}));

Event names must start with on so this will fire a onSaveFile
event to the Component with id btnSave . Just listen to it.

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