How to run a WebPage using XojoScript

Hello everyone.
Does anyone know how to run a WebPage using XojoScript.
I did the following test but it doesn’t work:

Var lsWebPageName As String = “wpHome.Show”
Self.XojoScript1.Context = Self
Self.XojoScript1.Source = lsWebPageName
Self.XojoScript1.Run

Your script can execute methods on the context. Add a method to the context that will open the page. Test it and make sure it works. Then make the script run the method.

Brandon, with all due respect, that is not a solution.
What’s the point of creating a method where the “wpHome.Show” command will be if the goal is for the command to be in the value of a string variable?
For example, I can have a list of WebPages in an array and be able to execute them based on the pointer passed as an argument.

It would be helpful if you could describe what you’re looking to do in a lot more detail.

My need is to have a list of web page names in a column of a WebListBox. Then, select the row and in the DoublePressed event of the WebListBox execute the chosen WebPage.

XojoScript is not suitable for this. In Xojo, you cannot transform a string into an object, even in XojoScript. Use a Select Case statement in DoublePressed and instantiate and show the corresponding web page.

1 Like

You can get a webpage by name:
https://documentation.xojo.com/api/web/websession.html#websession-pagewithname

You can also loop trough the webpages in the session. But you cannot check for which webpages are available. For that you may need to pre-fill a webpopupmenu or such.

Hi.
Reading the responses in this thread I realized that the XojoScript resource is overrated. It is powerful, but not so powerful if it has limitations such as not being able to instantiate a WepPage.

XojoWeb is a good tool. But, as I use it, I find myself encountering difficulties that I have to overcome using tricks that I have had to invent.

In this case, the WebSession class registers each instantiated WebPage in its Pages method, which makes sense. However, WebApplication should have its own Pages method in which it has registered each WebPage declared and ready to be instantiated. This resource (Pages method in WebApplication) would facilitate the creation of a WebPages main menu filtered according to permissions designated to a user.

You would like to use a Xojo Script to execute an action, but it`s not the right way to do it. No need to put together a trick, simply use the Xojo language to achieve your goal.

Xojo is very good to create Web Apps, API 2 was quite n enhancement.

My 2 cents.

Dear Gilles Plante.
I have programmed for 46 years, since I was 17 years old. I’ve been through basic, fortran, cobol, and others. Before “XojoWeb” I programmed (and continue programming) in Visual FoxPro 9 (VFP), and I can assure you that VFP, among its dozens of resources are string references (similar to XojoScript), with this I can execute anything: from external libraries to windows, open databases, use tables. Execute code written in a string, saved in string memories, written in a text file, or saved in varchar fields of a table, and execute them as XojoScript does. The only thing I can’t do, directly, is Web programming; Therefore, following the recommendation of a friend who programs in XojoDesktop, I decided to program in XojoWeb because I was looking for a graphical IDE that would give me the freedom to enter code. I tried programming with ScriptCase, with PHPMaker, even with RAD System Studio.

With this I want to tell you that, as a programmer, I am very creative and I try to build my bank of objects and classes to automate the development of an application as much as I can because the client needs quick developments and I need an orderly scheme so that I can focus. in the code and not in the details of menu, toolbar, grids, login, etc.
This does not mean that I am a great programming star, what I mean is that I know what I need as a programmer, if XojoWeb allows me to create all the resources that I have had with other programming languages in good time. On the contrary, if XojoWeb is not up to my standards I am not going to give it 6 stars.

So I have ample reference to rate a development tool like XojoWeb as good, NOT great. Furthermore, I have used XojoWeb since version 2019r3.2 and since XojoWeb 2020 in each new version they improve something and break others, and that’s how it is.

So you have to fear them when they announce each new version with bombardments, cakes, applause and cheers.

1 Like

Brandon already gave you the solution, but here are more details.

Assuming you have three WebPages called wpFoo, wpBar and wpBaz. Create a class called MyContext, for example, with this method:

Public Sub ShowPage(pageName As String)
  Var pages As New Dictionary("Foo" : wpFoo, "Bar" : wpBar, "Baz" : wpBaz)
  Var page As WebPage = pages.Lookup(pageName, Nil)
  
  If page <> Nil Then
    Session.CurrentPage.Close
    page.Show
  End If
End Sub

In the DoublePressed event of your WebListBox:

Var script As New XojoScript
script.Context = New MyContext // This is the class you've created above
script.Source = "ShowPage(""" + Me.CellTextAt(row, column) + """)"
script.Run

You don’t need XojoScript for any of this anyway.

4 Likes

Hi Ricardo Cruz.
Thank you for taking the time to write to me and suggest your code. However, don’t take this the wrong way, it’s no use; not because it doesn’t work but because it’s not practical.

The drawback of your solution, like the one I saw in this other thread, is this line:

Var pages As New Dictionary("Foo" : wpFoo, "Bar" : wpBar, "Baz" : wpBaz)

Why is it inconvenient?
Because all the WebPages of the application will be instantiated uselessly. That is, if my application had 50 WebPages, that line of code would instantiate all 50 pages, all at once.
As you should know, users have restrictions. A seller user, of the 50 pages in our case, is surely allowed to use 2 or 5 pages. It is a useless consumption of memory to instantiate the other pages that the user is not going to use. Multiply the same to a scale of 100 concurrent users.

The only solution is using SELECT CASE, or IF THEN ELSE. But that’s a bit from Fred Flintstone’s time (from Hanna and Barbera), it doesn’t contribute to automating a decent options menu which is what I want to achieve.

I still maintain my XojoWeb rating as good, but not great.

The key word in all my developments is “automation”. For example, automate the loading of a Grid, automate an edit, a delete, an update, automate the execution of a WebPage by registering its names in a table. Automate email sending. Automate… etc. etc The goal is to focus on the code and not on the execution scheme of the entire application.

There’s nothing in what you’re describing that is specific to Xojo Web - these are issues that many strictly-typed system run into. You could look at Xojo’s Introspection system, but honestly - for a first pass at a system like this, I suggest you buckle down an implement the straightforward Select Case solution, even though this also means you have to manually maintain a list of web pages somewhere that is used to populate the Listbox/Popup/whatever for the user. Later, as you become more comfortable with how Xojo operates, you can revisit this system and refine it if you wish.

Eric Williams.
I respect your opinion regarding XojoWeb. Surely you feel comfortable with this tool, I have no reason to doubt the excellent results you have achieved.

I am an analyst-programmer who seeks the automation of processes and I invest my time in creating my own development framework and in creating an execution framework for the client, in such a way that it allows me to only concentrate on the target code of the client’s requirement. customer. In other words, the client execution framework should be automatically adaptive, I only have to modify or add a WebPage, the rest should be done by the execution framework.

It is in these requirements that XojoWeb helps, but not much.

You could disable Implicit instances, or just use a Select Case statement instead.

1 Like

Then put the WebPage in the RowTag and call it this way.
image

image

1 Like

Ricardo Cruz.
Thanks for the suggestion. As citizens say, when they are going to choose between an evil politician and a worse one: “of the evils, the least.” For the moment I will stick with SELECT CASE, while the Xojo engineers take their time to realize that they should put much more attention into Web development like the competition does.

Dear Marius Dieter Noetzel,
Thank you for giving your time.
Your solution is similar to the Dictionary class. During the loading of the WebListBox all the WebPages of the application will be instantiated. But if you want to add only those that the user will need, you will be forced to use an IF THEN ELSE or a SELECT CASE.

The viable solution is for XojoScript to have the ability to run “webpage.show”, but we will only see that in an idyllic dream of a Xojo fan.

I think you misunderstand the use case for XojoScript. It is designed to be a highly sandboxed environment that allows an end user to write simple code that can be executed within the sandbox. It is not now, nor probably will ever be, usable in the way you envision. The creators of Xojo made certain design decisions for the language as a whole that make it work differently than languages such as VFP and PHP. Perhaps it doesn’t meet your needs.

2 Likes

Well you can use introspection and create an instance
https://documentation.xojo.com/api/language/constructorinfo.html#constructorinfo-invoke

so you could use a XojoScript context class that handles all this. but it’s doable, but how stable your could get it i’m not sure about that. It may be worth a try…

1 Like