Select Current Web Page Shown problem

I need to be able to to select the currently shown Web page among 14 that might be displayed and make a control visible. I can do this using session string variable I set in the Shown event and then use a Select Case for that variable to select a Web Page and make the control visible. However having to do a 14 item select case in multiple places and then maintain those if the number of pages increased over time was messy. What I wanted to do is have a single session method to identify the page and return that to be used to make the hidden control visible, but I get an error that says “Type WebPage” has no member named “ControlName”. I’ve put my code below and asking why I can’t return the Web Page and have this work. Also if there is a better way to do this that I’m not seeing I’d appreciate the feedback.

// sets the current page identifier in the variable PageShown
Sub Shown() Handles Shown
  If Not (Session.PageShown = "ComplaintForm") Then
    Session.PageShown = "ComplaintForm"
  End If
  Self.Label_BannerText.Text = "Complaint Form"
  Self.ImageView_JSphereLg.VerticalAlignment = WebImageViewer.VerticalAlignments.Center
  Self.ImageView_JSphereLg.HorizontalAlignment = WebImageViewer.HorizontalAlignments.Center
  If Session.LoggedIn = False Then
    Session.UserLoginShow("")
  Else
    Session.UserUpdateRightsDisplay
  End If
End Sub
// Gets the Web Page from the variable PageShown
Public Function GetWebPage() As WebPage
  Var wp As WebPage
  Select Case PageShown
  Case "Dashboard"
    wp = WebPage_Dashboard
  Case "ComplaintForm"
    wp = WebPage_ComplaintForm
  Case "ComplaintReports"
    wp = WebPage_ComplaintReports
  Case "CrackPeelHome"
    wp = WebPage_CrackPeelHome
  Case "CrackPeelRequestForm"
    wp = WebPage_CrackPeelRequestForm
  Case "CrackPeelFormViewer"
    wp = WebPage_CrackPeelFormViewer
  Case "CrackPeelProductionReport"
    wp = WebPage_CrackPeelProductionReport
  Case "CrackPeelConsolidatedReport"
    wp = WebPage_CrackPeelConsolidatedReport
  Case "ReprintRepairHome"
    wp = WebPage_ReprintRepairHome
  Case "ReprintRepairRequestForm"
    wp = WebPage_ReprintRepairRequestForm
  Case "ReprintRepairFormViewer"
    wp = WebPage_ReprintRepairFormViewer
  Case "ReprintRepairManagementReports"
    wp = WebPage_ReprintRepairManagementReports
  Case "ReprintRepairProductionReport"
    wp = WebPage_ReprintRepairProductionReport
  End Select
  Return wp
End Function
// Makes the ImageView  aof a spinning sphere visible before showing the Login Dialog
Public Sub UserLoginShow(option As String)
  Var pg As WebPage
  pg = GetWebPage
  pg.ImageView_JSphereLg.Visible = True
  LoggedIn = False
  UserUpdateRights
  Login = New LoginDialog
  Login.UserLoginCC1.Option = option
  Login.Show
End Sub

Session.UserLoginShow, line 3
Type “WebPage” has no member named "ImageView_JSphereLg"
pg.ImageView_JSphereLg.Visible = True

I would create a class Interface and add a method to show the image. Each page would implement that interface and in the method show the image. Then you can refer to the page via the interface to execute the method.

Any tip on where I can find an example of something similar or do I need to purely rely on the help documentation. I’ve never implemented a class interface before.

Check out the examples in the Design Patterns folder that comes with Xojo. At least the Decorator example has a class interface.

Thanks for the tip Beatrix!

I’m struggling to make a Class Interface work. Probably because I don’t completely understand it. To start with I have added a Class Interface to the Project called JSphere and in it I have added two methods called ShowJSphere and HideJSphere, but I can’t seem to be able to add any code to those Methods. I’m trying to understand what is happening in the Decorator example and how that relates to what I want to happen so I’ll describe that here to see if someone can point me in the right direction with the sample project I have created to figure this out.

In my toolbar on each page is a Login Button. When pressed I want whatever the current page is to make visible the WebImageViewer control called ImageView_JSphere, that is on the page but not visible, by calling a session method called ToolbarButtonPressed passing the ToolbarButton .Tag to that method.

Public Sub ToolbarButtonPressed(buttontag As String)
  Select Case buttontag
  Case "1"
    WebPage1.Show
  Case "2"
    WebPage2.Show
  Case "Login"
    // Something here that implements the Class Interface called JSphere
    // to show ImageView_JSphere on the current Web page
    LoginDialog = New WebDialog_Login
    LoginDialog.Show
  End Select
End Sub

How do I address the Class Interface to add the code ImageView_JSphere.Visible = True to the Method ShowJSphere and mageView_JSphere.Visible = False to the Method HideJSphere?
Do I need to select the Class Interface in each of the Web pages? (it shows up in the list and can be checked)

I’m missing something important I know that I’m just not understanding about the Decorator.xojo_binary_project to make this work. I would appreciate a little more guidance if someone would be so kind.

You can’t add code to class interfaces. The code is all in the classes that implement the class interface.

A class interface is for making sure that different classes implement the same behaviour. Classic usage for class interfaces are iterators.

while theMailIterator.hasNextObject

theEmail = theMailIterator.getNextObject
'lots of other code
wend

theMailIterator is a class interface. With the interface I can treat different email clients the same. The iterator knows how to get an email from an email client. Here in the main routine I just need to know that there is a next object and that somehow I can get the data from the object.

I can create the interface and assign the interface to the Web pages and add the Interface Methods to the web pages but when I try to execute them from a session method I get a nil object exception. I’m really struggling to make this work.

However, I did find an alternative simple method to make the WebImageViewer visible by adding a WebImageViewer variable to the Session and making it the current Web Page ImageView_JSphere when the page is shown. From that I can show or hide it from a session method.

That doesn’t mean I still wouldn’t like to solve why I could not get it to work using a class interface. Here is a link to the test project. TestWebApp If you can advise me why it doesn’t work I would appreciate it.

Updated project

Hi Tom,

Search for comments beginning with //Axis to see the changes made.

HTH
Wayne

1 Like

Wayne,

Thanks for taking the time to show me what was missing. The reference to the page via its class interface as a session variable makes sense. Now that I have a practical application of a class interface I’ll be better able to try using one again for a different class if the need arises.