Iframe

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
JayGoo83
Profound User
Posts: 36
Joined: Fri Jul 17, 2020 12:52 pm
First Name: Jason
Last Name: Guzik
Company Name: 3Linc
Contact:

Iframe

Post by JayGoo83 »

I have an iframe that is another profound RPG program. It refreshes itself every 6 seconds as it makes an API call for real time data. The problem is that whenever it refreshes, the page jumps back to the top. I have several grids below this Iframe, so i would like if I'm somewhere else on the page when the iframe reloads it doesn't jump back to the top. Thanks in advance.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Iframe

Post by Scott Klement »

When you "refresh" the screen, what are you doing? Are you submitting control to the RPG program, and it is doing a fresh EXFMT (or WRITE/READ)? If so, you're telling it to completely wipe out and delete everything in the iframe, then re-draw it from scratch. There's nothing staying on the screen that you can just "keep where it was".

You would need some sort of approach where you run code before refreshing the screen that retrieves the scrollbar position and saves it somewhere (maybe in sessionStorage or similar) and then when it reloads, re-sets that position. But, I haven't done that before... and I can't say I've ever seen someone else do it, either. Should be possible, though.

Now... take this with a grain of salt, since I know absolutely nothing about your application... but the way I'd typically do something like this is NOT to submit the screen, but to fire a background AJAX request that retrieves updated data, and then just update the existing screen in-place. If you did something like that, you wouldn't have to worry about the scrollbar position changing. Heck, you may even be able to eliminate the iframe entirely, depending on what its purpose is.
JayGoo83
Profound User
Posts: 36
Joined: Fri Jul 17, 2020 12:52 pm
First Name: Jason
Last Name: Guzik
Company Name: 3Linc
Contact:

Re: Iframe

Post by JayGoo83 »

Yes when i refresh the iframe i am triggering a click event, handing control back RPG, calling my API and then running EXFMT. I had thought that since i was only doing that within the iframe it wouldn't effect the parent window.

I would love to just do an Ajax request and update the information. The problem is that I don't know how to do in profound. I reached out a while ago and was told i need to create my own separate web service program. To be completely honest i don't really know what that means and haven't had the time to look into it. Honestly if there was a resource to show me what i need to do to start making ajax requests it would make my whole world a lot better.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Iframe

Post by Scott Klement »

I used to teach a class at the Profound Logic User Seminar (PLUS) about how to make AJAX requests from Profound UI. I'm not doing it this year, though, since PLUS is stripped down due to Covid.

Basically, it works like this:

1) You use the JavaScript ability to make an HTTP request. You can use whatever AJAX library you're comfortable with, call the built-in browser routines (such as XHR or the newer routines such as fetch, et al.) yourself, or you can use the AJAX routines that we provide in the PUI runtime. Doesn't matter, any will work.

2) On the server side, you write a routine to process the request. This would be a stateless request, most likely returning its output as JSON. (Though, any format can work, you just have to code the client side accordingly.) Universal Display files are a good way if you're an RPGer, but other approaches like CGIDEV2 work fine. Or you can use another language such as Node.js, PHP, Java, what ever works for you.

3) Back on the client side, when the data comes back from the request, you can use our APIs like pui.set(), et al, to update the screen.

If you're familiar with AJAX, this really shouldn't be hard to understand. It's the same as it would be in any web application, except that when the data comes back you use pui.set(), applyProperty(), grid.setDataValue(), etc when the data comes back instead of manipulating the DOM directly. The rest of the process is the same.
JayGoo83
Profound User
Posts: 36
Joined: Fri Jul 17, 2020 12:52 pm
First Name: Jason
Last Name: Guzik
Company Name: 3Linc
Contact:

Re: Iframe

Post by JayGoo83 »

Hey Scott. I guess my question is how do i actually call my program from my ajax request?
So i am coding in RPG. I have a dashboard program that calls the request onload. I also wrote a program that makes an API calls and builds a JSON response. Lets say library is ABC for both programs.
ABC/DASH calls ABC/JSON, ABC/JSON responds and my success will use pui.set etc...
For my request URL, i tried
http://ip:port/profoundui/start?pgm=ABC/JSON and it didn't work
I tried using Profound API/URI mapper tool and then did something like:
http://ip:port/profoundui/universal/PGM and pointed it to my ABC/JSON

Is there something else i am missing or something else i can read?
Thanks in advance
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Iframe

Post by Scott Klement »

JayGoo83 wrote:Hey Scott. I guess my question is how do i actually call my program from my ajax request?

That was my point #1, above. You can use a 3rd party AJAX library, write your own XHR, or call using our AJAX routines... https://docs.profoundlogic.com/x/4wBK

You made it sound like you've done AJAX before, but not in Profound UI -- and that it was harder in Profound UI. In reality, its exactly the same as it would be anywhere else.
JayGoo83 wrote:So i am coding in RPG. I have a dashboard program that calls the request onload. I also wrote a program that makes an API calls and builds a JSON response. Lets say library is ABC for both programs.
ABC/DASH calls ABC/JSON, ABC/JSON responds and my success will use pui.set etc...
Not sure I followed that. What do you mean by "a program that makes API calls"? Or ABC/DASH, ABC/JSON, ABC/JSON -- I really don't understand what these are. Is ABC a library? Or is this an IFS path? a path in a URL? I'm lost on this part.
JayGoo83 wrote:For my request URL, i tried
http://ip:port/profoundui/start?pgm=ABC/JSON and it didn't work
I tried using Profound API/URI mapper tool and then did something like:
http://ip:port/profoundui/universal/PGM and pointed it to my ABC/JSON
If you're using Univeral display files, it should the /universal/PGM (though, "PGM" isn't really accurate) style URL. You definitely don't want to use /start?pgm= that makes zero sense.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest