webPage Constructor and web API controls...

I know there is something goofy with using constructors for web pages, but I didn’t immediately see a way around it in this case.

The problem is that the setupHTML event of webAPI controls fires when you create the new window and not when you show it. I can’t say something like

w = new myWindowWithAPIControl
w.setupMyControl( someObjectToDisplay)

as the setupHTML event fires immediately upon the new. I need the control to show it’s content upon load and not show up initially empty and then be populated later. Otherwise whats the point of having the setupHTML event. So I need to know what object it’s connected to when the setupHTML event fires.

I tried passing it into a constructor for the window as that does happen before the other. This caused all sorts of weirdness like the width of the window being completely wrong as if it was adding the initial size to the current size or something. It was almost, but not quite twice the actual width I had set for the window and caused all locked controls to set themselves up for that much larger size forever so you couldn’t see them all. It never loaded it’s style data for the window background either. Very strange. Yes, I called the Super.constructor :wink: So that didn’t work at all.

What I finally did was to create a property in the Session object. Before I create the window instance I put the object I want it to display for the page into the session object property and then create the page, then the setupHTML event can also access the session and get the reference to the object out of it.

This works, but feels like a hack and seems as if I’m totally missing the point.

Has anyone else hit this problem and is there any better way around it? I do not want the page to load with an empty display and then to have it appear after the shown event. That makes the page feel much slower and should not be necessary as I can send all the proper displays if I know what object I’m referencing during the SetupHTML event.

Can anyone tell if WebEdition 2.0 has a saner event order for such things? Or am I missing a more obvious solution?

That’s the desired behavior though. If you want to do something when you show the control, use the Shown event. SetupHTML is for setting up the HTML for the DOM object.

I don’t understand what the problem is.

This is a side effect of dynamically loaded DOM objects. If you want to load something into it before displaying it (ie you have cumbersome javascript to perform) load it out of view (-9001 top would work).

But you can reference the control during SetupHTML, use me.ControlID

You already know the answer to that.

I would be happy to help you figure out the best way to implement what you want to do. However, I need to understand what you really are trying to do. I find that describing your end result rather than the technologies you think you need to use works best.

You and I are either talking about completely different problems or we don’t understand each other at all :wink:

The shown event happens potentially LONG (well, a few very important seconds) after the page has actually displayed to the user. I do not want to show an empty list and then have it populate some seconds later during the shown event. I can do this, no problem, code wise this is simple but user wise this is poison.

there is absolutely no reason I have to display an empty page, wait for the shown event and then send the data I want to display. I have this wonderful setupHTML event, i can fill in the initial data as it goes out for that and not just setup the control empty.

If I do that the display is so fast as to be almost instantaneous. If you send an empty display in the setupHTML event and then send javascript to populate it in the shown event you’ll get complaints from users as to why it takes so long, even though it’s only a few seconds, it’s unnecessary seconds when I can easily populate the display in it’s initial sending to the browser.

As far as the “what object I am referencing” question, thats not the DOM object or anything that can be referenced with the controlID, it’s an internal object to my program that holds the data I want to display. The data I want to push out during the SetupHTML event.

Think of it as if you were creating a replacement (for some unknowable reason) for the label control. You want to set the initial contents of the label. You can’t do this with the regular webAPI. There is absolutely zero reason why you couldn’t send the initial value for the label in the SetupHTML method except that you can’t tell it what that value should be as the SetupHTML event happens before you can do anything with the page at all. What will happen is that your label loads as empty, and then when the shown event happens you can send the update. So you page loads empty, then a second, or potentially MANY seconds later, the values pop into the various labels you’ve created. This is fine if you only have one label on the page but gets VERY slow if you’re waiting for shown events for one a a dozen or 50 of them. The whole reason I’m going with a webAPI control is that I can send it in the SetupHTML event and it displays almost instantly. Anything else is user happiness kryptonite.

Maybe this will help:

Not entirely. You may be seeing a delay from the round trip, but if it’s up in the timeframe of seconds it’s an issue specific to this case. From the documentation: “This event is called once your control has been received and created by the browser.”

We can’t expect the control to exist in the user’s browser before Shown, and we use the Shown event to know when it is ready.

Yes there is. If your control was designed to be manipulated in the DOM (meaning the data is manipulated directly in the DOM and not with a data control, like using a Listbox to store your data instead of just displaying it) you need the control to exist in the DOM before you can do anything with it.

If your control was designed to display data it’s sent, you would be able to send the data in the SetupHTML event. This is shown by the documentation with the Hello, World! example.

Being able to use me in that event means that you have access to the Xojo object as well. If you want to use data on the object you can, create a property to hold it and use the property value during SetupHTML.

Yes… you can, and it happens to be part of the first example in the WebControlSDK.pdf documentation.

Again, I’m happy to help, but you’ve also managed to completely avoid the question of “what exactly are you trying to do?” (as in, what is your control, what do you expect from it, and how have you implemented things so far?) Each custom control is different, and what may work in one instance may not work for another.

perhaps I can help… if I understand, of course.

This is more a typical Xojo question rather than a [web] question.

Imagine you had a class that you subclassed. In your subclass you can create an event handler where you’re supposed to set things up.

The only problem is, the event gets raised in the super class’s constructor and the constructor doesn’t let you send any parameters.

So your code, in the event handler, needs some additional information, but it gets fired before you have a chance to supply the additional information.

– do I have that right – ?

James. what about subclassing and creating your own overloaded constructor that includes a parameter? Also create a property in your subclass. Then in your new constructor you load the passed parameter into the property and then call the super’s constructor.

It still feels like a bit of a hack but it’s a bit more OOP and encapsulated (and re-entrant safe) than attaching it to the session…

Here’s a very simple example of how to set an initial value if you were creating a label-like WebControlWrapper: https://pastebin.com/fsTzB8m0

Paste it into a text file with the extension .xojo_code and drag it into the Navigator.

Warnings/disclaimer: This control does not function for any purpose except to show how to use an initial value!

I think you will find yourself in a world of hurt eventually. The Xojo Web built-in controls are not very suitable for tampering with their events.

You would be best served reproducing the control as a custom control providing the functionality you desire.