-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
<window
apply="org.zkoss.bind.BindComposer" closable="true"
onClose="@command('close')"
viewModel="@id('vm') @init('viewmodels.VM')">
<custom-attributes RL="${arg.resultListener}" />
<style>
textarea[name=versioDdescription]
{
resize: none;
}
</style>
<hbox>
<label>Version</label>
<textbox value="@bind(vm.view.version)"
maxlength="5" />
</hbox>
<space />
<vbox width="100%">
<hbox>
<fileupload label="Upload"
onUpload="@command('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);
}
</script>
<label
value="@load(vm.fileName eq null ? 'No File' : vm.fileName)" />
</hbox>
<space />
<label>Description</label>
<script type="text/javascript">
</script>
<hbox pack="center" width="100%">
<textbox name = "versioDdescription" rows="8" cols="70"
value="@bind(vm.view.description)" maxlength="250"/>
</hbox>
<button label="Save"
onClick="@command('save',resultListener=RL)" />
</vbox>
</window>
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)".
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)
https://github.com/zkoss/zk/blob/master/zul/src/archive/metainfo/mesg/msgzul.properties#L77
my adding this to your zk-label.properties
MZul.2105=The file is larger than 2MB.
Asked: 2018-05-02 19:38:39 +0800
Seen: 9 times
Last updated: May 08 '18