-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I need your help as I got stuck:
In a "@Init
" method of a mvvm view model I might detect an error, that makes it impossible to process the current page.
So I might try to redirect to an error page by exceution.sendRedirect(...)
and return
.
Unfortunately though, all mvvm bindings (getters
) and even @AfterCompose
are processed BEFORE the redirect finally takes place.
So there are a lot of null pointers thrown here and there.
My dumb question now: How can I make sure that the redirect is processed without any further processing of the current page?
And no: I do not like to put an "if (error) return;
" on each getter method.
You can throw a runtime exception to break the normal binding process. Then zk doesn't proceed the subsequent data binding on that page and doesn't produce errors:
@Init()
public void init(){
if (!isValidationPassed()){
throw new IllegalStateException("failed);
}
}
Then handle this error according to https://www.zkoss.org/wiki/ZKDeveloper%27sReference/UIPatterns/ErrorHandling
Assuming the error is handled by error.zul
, you can call sendRedirect() in error.zul
or just specify the target page as the error handling page.
Hey there.
It's a bit of a tough one, because the binder is designed to be robust and "keep going" even if some of the bindings trigger exceptions. The binder will still attempt to read the rest of the properties
When an exception is thrown in a getter of the VM during initial page rendering, the exception will be passed to the error page (if any), so that will interrupt page load anyway.
If you are triggering this exception after page load (if the binding error occur after a user event like a click), it will bubble up to org.zkoss.zk.ui.impl.UiEngineImpl.handleError(Throwable, UiVisualizer, List<Throwable>)
which will just add it to the list of errors to display after the end of the current execution.
Is the issue that "many exceptions are shown in the popup on screen"? if that's the case, you can simply implement your own error popup:
https://www.zkoss.org/wiki/ZKConfigurationReference/zk.xml/Theerror-pageElement
Asked: 2023-08-30 00:09:29 +0800
Seen: 12 times
Last updated: Sep 08
Databinding and auto-complete on combobox
Composite component and bind in ZK 6
How to detach / reattach MVVM windows?
Is there a way to resolve view model properties as input to client side javascripts?
How can I synchronize data in a ListBox in MVVM ? [closed]
MVVM Validator: class not found ? [closed]
How to Call Child ViewModel Method from Parent Window? [closed]