B4J Question [ABMaterial] how to start navigation to a specific page?

rbirago

Active Member
Licensed User
Longtime User
In the samples the navigation starts always from the HomePage. Clicking on a login button or on a login menu item the user enters the application...but what if I want to directly point a specific page (using of course a specific URL)? I have to identify the called URL (is the incoming URL available somewhere?), access the login and then jump to the specified page.
So: how to catch the called URL and possibly the URL attached params?
thanks
Roberto
 

Harris

Expert
Licensed User
Longtime User
In this example, I handle the appropriate page from login based on the users admin privileges.
This sub is found in my ABMLoginHandler module.

processlogin:
Sub processlogin(page As ABMPage, user As Map)
    
    page.ws.Session.SetAttribute("authType", "local")
    page.ws.Session.SetAttribute("authName", user.Get("userlogin"))
    page.ws.Session.SetAttribute("IsAuthorized", "true")
    
    Dim amp As Int = user.Get("adminpriv")
    Log(" **** what is admin setting: "&amp)
    If amp = 1 Then
        page.ws.Session.SetAttribute("UserType", "1")     ' is administrator
    Else
        page.ws.Session.SetAttribute("UserType", "0" )
    End If
    
    
    'Dim usrt As String = ABMShared.GetUsrType( user.Get("usertype") )
                    
    'page.ws.Session.SetAttribute("UserType", usrt )    ' lowercase!
    page.ws.Session.SetAttribute("UserID", "" & user.Get("userid") ) ' lowercase!
    page.ws.Session.SetAttribute("UserRows",   user.Get("userrows") ) ' lowercase!
    page.ws.Session.SetAttribute("comp_id",   user.Get("comp_id") ) ' lowercase!

    Maincomp_id = user.Get("comp_id")
    page.ws.Session.SetAttribute("orgtype", -1 ) ' lowercase!

    Dim SQL As SQL = DBM.GetSQL
    Dim memb As List = DBM.SQLSelect(SQL,  "SELECT * FROM member WHERE pk = " & Maincomp_id ,Null)
    If memb.Size > 0 Then
        Dim m As Map = memb.Get(0)
        page.ws.Session.SetAttribute( "orgtype",m.Get("otype")) ' lowercase!
    End If
    DBM.CloseSQL(SQL)
    
    Log(" ............ Handled login User: "& user.Get("userid")&"  UserType: "&amp&" org type: "&page.ws.Session.GetAttribute2("orgtype",-1))
                            
    Dim downloadfolder As String = File.Combine(File.DirApp, "/www/" & ABMShared.AppName & "/uploads/"&"comp_"&Maincomp_id)
    Dim tdown As String = downloadfolder&"\comp_"&Maincomp_id
    File.MakeDir(downloadfolder, "")'  "comp_"&Maincomp_id)


    page.CloseModalSheet("login")

' where do we go from here?

    If amp = "1" Then
        ABMShared.NavigateToPage(page.ws,  "x123Login",  "../AboutPage")
    Else
        ABMShared.NavigateToPage(page.ws,  "x123Login",  "../CouncilPage")
    End If

    
End Sub
 
Upvote 0

rbirago

Active Member
Licensed User
Longtime User
Perhaps I have not explained the question:
I want to manage the first URL the user sets to enter the app that normally in B4J Server is available by ServletRequest.
I have to manage this URL and the optional parameters when the user attempts to enter the app (when the session is created).
In which point can I manage the ServletRequest?
Or is there another way to get these data from ABM?
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
In ABMApplication module - where it all starts....

Where to go from here, based on your question is beyond my level of understanding...

B4X:
Sub Class_Globals
    ' change to match you app   
    Private InitialPage As String = "HomePage"

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    Log("ABM App - Connected")
    ws = WebSocket1
    ' connect our page with the websocket   
    'AppPage.SetWebSocket(ws)
'----------------------MODIFICATION-------------------------------
    ABMPageId = ABM.GetPageID(AppPage, ABMShared.AppName,ws)
    Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds) 'ignore
    '----------------------MODIFICATION-------------------------------
    If session.IsNew Then
        session.Invalidate
        Log(" page is new - navigating to: ./ ")
        ABMShared.NavigateToPage(ws, "", "./")
        Return
    End If

    ' Prepare the page IMPORTANT!
    AppPage.Prepare   
    ConnectPage
    ' navigate to the first page
    Log(" what is login: "&ABMShared.NeedsAuthorization )
    ws.session.SetAttribute("IsAuthorized2020", "true")
    
    ABMShared.NavigateToPage(ws,ABMPageId, "./" & InitialPage)
End Sub
 
Upvote 0
Top