JS don`t show alert message after second open window

asked 2018-05-02 19:38:39 +0800

Radoslav86 gravatar image Radoslav86
13 3

I have zul where I open new window with new VM. In new Window i hawe js code where i catch error for to big file

apply="org.zkoss.bind.BindComposer" closable="true"

viewModel="@id('vm') @init('viewmodels.VM')">

<custom-attributes RL="${arg.resultListener}" />
            resize: none; 
    <textbox value="@bind(vm.view.version)"
        maxlength="5" />
<space />
<vbox width="100%">
        <fileupload label="Upload"
        <script type="text/javascript">
            var oldAlert = jq.alert; 
            jq.alert = function (msg, opts)
            oldAlert(msg, opts); 
             if (!msg.indexOf('the request was rejected because its size' || 'Failed to mount: Invalid or unexpected token')) 
             oldAlert('The file is larger than 2MB. ', opts); 
            value="@load(vm.fileName eq null ? 'No File' : vm.fileName)" />
    <space />
        <script type="text/javascript">

    <hbox pack="center" width="100%">
        <textbox name = "versioDdescription" rows="8" cols="70"
            value="@bind(vm.view.description)" maxlength="250"/>
    <button label="Save"
        onClick="@command('save',resultListener=RL)" />


When i open this window for first time and upload file larger than 2MB message is show, but if i close window and immediately open again if i upload file larger than 2MB message is not show.File is not upload but in stack trace i have exception "org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (40738509) exceeds the configured maximum (2097152)".

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-08 19:36:08 +0800

cor3000 gravatar image cor3000
4089 1 7
ZK Team

I can't fully follow what you are trying to achieve there since the JS code you wrote doesn't produce a useful result. See the line below. I think you should call indexOf again after the ||:

if (!msg.indexOf('the request was rejected because its size' || 'Failed to mount: Invalid or unexpected token'))

Also when opening the same window multiple times you are overriding the same function again while keeping the oldAlert at the global scope resulting in infite recursion / and stack overflow JS errors.

So here a working version of what I inferred you might intend to do (correct me if I'm wrong): http://zkfiddle.org/sample/13vm1c7/1-override-alert-function

BTW: Did you try overriding the max size error message using the default way? (available since ZK 8.0.0)


my adding this to your zk-label.properties

MZul.2105=The file is larger than 2MB.
link publish delete flag offensive 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




Asked: 2018-05-02 19:38:39 +0800

Seen: 4 times

Last updated: May 08

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