0

Zk how to call Java method from javascript?

asked 2016-10-24 10:04:43 +0800

psingh gravatar image psingh flag of India
963 8

updated 2016-10-24 17:15:25 +0800

I am using dropupload and browse functionality to upload the file. I am checking for maximum file size in both the functionalities. In case if the file size exceeded I want to call my java method to show the error message

In ZUL File

<dropupload maxsize="51200" id="fileUpload"></dropupload>

<script defer="true">
<![CDATA[  
        var status = false;
        var oldAlert = jq.alert;
        jq.alert = function (msg, opts) {
        alert(msg);
            if (!msg.indexOf('the request was rejected because its size')){
                     status = true;

            }
            else{
                //oldAlert(msg, opts);
                status = true;
                }


            if (status) {
               alert(status);
                zAu.send(new zk.Event(zk.Widget.$('#fileUpload'), 'onDropFile', status, {toServer:true}));

            }
        }
        ]]>
</script>

In View Model,

@Listen("onDropFile = #fileUpload")
public void onDropFile( Event evt) {
    if (evt.getData() != null) {
        showError("Upload File size is exceeded"); 
    }

}

Can anyone how this functionality will work out or is there any other way to call java method from ZUl file using JAVASVRIPT?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-10-24 13:19:19 +0800

Darksu gravatar image Darksu
1991 1 4

Hello psingh,

You can refer to this old post:

http://forum.zkoss.org/question/52893/call-java-method-through-javascript/?sort=oldest&page=2#sort-top

Best Regards,

Darksu

link publish delete flag offensive edit

Comments

The above given javascript function calls only when the uploaded file is greater than 51200 and then ZK error message is popped up. I am catching the error message and wants to call the java method from this function. But in my case, I am not able to call the method from this javascript function.

psingh ( 2016-10-24 17:11:34 +0800 )edit

Is there any other way to call the java method from this override error message?

psingh ( 2016-10-24 17:13:03 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-10-24 10:04:43 +0800

Seen: 54 times

Last updated: Oct 24 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More