If a Codeless block has a bottom connection it means the next block will be executed after the block, of course, if the is not failed with an exception.
In order to interrupt execution you have a few options/approaches, take a look at some of them:
On Page Enter now looks like this based on your feedback -
The redirect works, and the print statement isn’t running. However, I am still getting error related to the page that the redirect was on. I am not clear why those are being referenced since the browser isn’t on that page any longer -
It looks like there is a code execution order error. In testing, I set On Before Page Enter to redirect. This should be the very first thing to execute, right -
In one of the simple models (from the Marketplace), the class list logic prints out a message -
When the page loads, the redirect happens, but the class list logic also fires (along with other code). None of the page variables are set up, because we’re supposed to be leaving the page, so everything errors -
the On Before Page Enter event is async and it doesn’t block the render phase, so it means the page is being rendered anyway that’s why you can see that components are going to be rendered even if you interrupted the On Before Page Enter event
In order to prevent rendering any inner component on the page you can use the following approach:
in the On Before Page Enter event in case you want to render the page you set some property to the page data, for instance, ready with the value true
for all top-level components on the page you use On Visibility Logic handler you use (data-binding) the. ready value from the PageData
in the UI Designer you switch off the Display setting for all the top-level components to prevent rending them, but they will be rendered only when the ready value is true in the PageData
pay attention to for components with Display=False it still runs its handlers but doesn’t render (create) children and doesn’t display the component
I tried what you suggested and have reduced the errors from 50 to 4.
I am now stuck that the errors are coming from a component. The page header is used on every page. On every other page, I don’t have to wrap it in a page ready check for it to work.
Again this feels too complicated to do all these checks when I want to do one simple authorization check and leave the page if the user isn’t authorized. This feels like building around a problem with the execution order.
You can also correct the location of the error. Cannot read properties of undefiend
The error occurs because we are trying to take a property from a non-existent thing.
All the properties are initialized On Before Page Enter unless the user is not logged in. In that case, the page properties are not initialized because the browser should leave the page before it matters.
For reasons I have still not received a clear answer to, “before” doesn’t apply here.
I can implement solution 1; it just seems redundant and a workaround to the execution order issue.
That feels like a lot of work when all I want to do is check if a user is logged in and if not redirect them.
It is no true.
You can do something like this:
Thank you for the clarification on checking the current user.
The example of redirecting does not work. If you scroll up, I tried to do a redirect as the first thing On Before Page Enter and still received errors.
I was told the code is running asynchronously, which I do see in testing, so “before” in backendless UI-Builder isn’t really “before” as far as I can tell.
@vladimir-upirov gave me tips on handling asynchronous loads sometime back… I thought I would summarise the pattern I am using to handle page object definition/references during page loads and data loads to make things a little easier to implement across multiple pages.
Backendless rules:
Any database loads cause components on a page to refresh UI/Logic and data binding
Components that are not displayed don’t fire a UI/Logic or binding refresh
Yep the Page Load events (On Before or On Enter) are not synchronous in operation. Which makes sense if components need to respond to changes. Blocking of events is not possible and is a feature of the UI/Data Binding framework.
The following pattern will help to not get undefined objects during Page Load events as well as redirect someone to another page or show an error if they are not logged in:
Place standard components and reusable components within a parent Workspace block.
At the beginning of the page load hide the Workspace block with Visibility Logic by setting pageLoaded = false. This will hide all page components - refresh of UI/Logic or data binding will not occur. Therefore no undefined object errors will occur during page load.
Validate user, load database, set all objects and values needed.
Show Workspace block (pageLoaded = true) - all refreshes for UI/Logic and data binding will now occur.
Hi @Tim_Jones
Out of curiosity: why do you have a problem with these errors occurring after navigating to another page? Yes, they do occur, but they do not affect your users, or? It is also a best practice to catch errors with try-catch blocks.