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 -
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.
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.
@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.
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.