0

Stop all mvvm binding (+ other) events

asked 2023-08-30 00:09:29 +0800

holos gravatar image holos
27 5

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.

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2023-09-08 11:02:49 +0800

hawk gravatar image hawk
3185 1 5
http://hawkphoenix.blogsp... ZK Team

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.

link publish delete flag offensive edit
0

answered 2023-08-31 14:59:30 +0800

holos gravatar image holos
27 5

Is there anybody out there?

link publish delete flag offensive edit
0

answered 2023-09-07 23:51:18 +0800

MDuchemin gravatar image MDuchemin
2390 1 6
ZK Team

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

link publish delete flag offensive edit

Comments

My confusion here might come due to the fact that all your documentation mentions things like - WEB-INF/web.xml <error-page> or - <location>/WEB-INF/sys/error.zul</location>

I am using SpringBoot and I do not know where to find WEB-INF and web.xml

holos ( 2023-09-09 00:48:21 +0800 )edit

you can specify any path that your application can access

hawk ( 2023-09-11 10:20:52 +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: 2023-08-30 00:09:29 +0800

Seen: 12 times

Last updated: Sep 08

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