Is there a stable solution for loading images in SAP UI5 App? - sapui5

Images folder contain many images like xxx.png, yyy.png, etc.
Image src="./images/xxx.png" works very well when I am testing and after deploying to SCP. But, the same doesn't work when I register the app to Launchpad and open it from there. Why does the images don't load?
I see the following the in the network:
Component.js is getting loaded from
https://xxxxxx-yyyyy.dispatcher.eu3.hana.ondemand.com/sap/fiori/workbox/Component.js?ts=1.0.143 with 200 status
But the images are trying to get load from
https://xxxxxx-yyyyy.dispatcher.eu3.hana.ondemand.com/images/xxx.png
https://xxxxxx-yyyyy.dispatcher.eu3.hana.ondemand.com/images/yyy.png which results in 404. Instead the hit should I have been on the following url.
https://xxxxxx-yyyyy.dispatcher.eu3.hana.ondemand.com/images/sap/fiori/workbox/images/xxx.png
I tried changing the Image src to src="./images/xxx.png" and src="/images/yyy.png". But, same old URLs are hit and results in 404.
Why does this happen so? Why does component.js and images are loaded from different root? I found many answers suggesting to use jQuery.sap.getModulePath("com.xxx.Component") but that didn't help me the least. It returned me https://sapui5.hana.ondemand.com/resources/com/xxx/Component which is of no use.

Old post but let me try to help you.
In order to retrieve files from your local project folder structure, you need to calculate the correct path to them. This is relevant for the FLP environment as apps get dynamic paths assigned when loaded.
sap.ui.require.toUrl is the magic function that should do the trick for you.
This function expects a path as input parameter and will translate it into a working path inside the FLP. See the method description.
Example
<Image src="{
value: 'your/name/space/images/xxx.png',
formatter: 'sap.ui.require.toUrl'
}" />
sap.ui.require.toUrl is replacing the deprecated jQuery.sap.getModulePath since UI5 1.58.
And since version 1.61, it is possible to pass static values to formatter functions via value in property binding as mentioned in the question Pass Static Value to Formatter Parameters in XML View.
If the formatter is no way to go for you, you can try to call the function within the controller and store the calculated path in a local JSONModel. I did not test this but the principle should be the same.
Good Luck!
P.S.; First Post. Any feedback on what to improve is very welcome :)

Related

Setting up Dynamic Links in Firebase with Wordpress site

I am really struggling here... All I actually want to achieve is that I can get the Generate-Strong-Password function inside my app but that is actually harder than I thought.
I learned that I should go with Firebase Dynamic Links because I have a Wordpress-Website from All-Inkl.com.
I followed this Tutorial and there is actually an Apple-Site-Association-File at the moment. But I can't access my Website anymore as it looks like this:
Inside my Firebase Project I am getting this error which says that there not all the necessary "A-Files" are inside my Website:
My DNS-Settings:
I've been struggling for weeks now to get this done so if anyone has any idea how I can fix it I would be extremely grateful!! (btw, I am a total newbie when it comes to websites; I know my way around Swift though)
It seems that different domain providers accept different values for DNS entries ('A records' = 'A-Datensätze', in this case).
Try editing the entries for the Host field (which currently hold your website's URL) to one of the 'common inputs' listed here: https://firebase.google.com/docs/hosting/custom-domain?hl=de#domain-key
As the URL to your site doesn't seem to be what your provider accepts, I would suggest you try replacing it with the next option, i.e. replacing it with # .
Hope this helps solving your issue!

How to debug with createJS's objects

I am using createJS for a game, but when I debug the code with console, I got all objects displayed as an a. Then I have no idea what the object really is.
What does the a here mean? And what's the best way to debug these code?
This is due to the minified source. Instead, use the combined source. You can get a combined version of each library in GitHub, which is one file containing all the classes, but just appended, instead of minified.
If you are using the full combined suite on the CDN, then you can change the path to .combined instead of .min: https://code.createjs.com/createjs-2014.12.12.combined.js
Cheers.

Dynamically loaded javascript doesn't show in sources panel?

For example, I have an ajax request and it returns <script src='buggy.js'></script>.
Problem is, it doesn't show up in sources or resources panel. That means I can't do all the cool stuffs like adding breakpoint and inspecting the elements as they run.
I could only see the source of the js file under the Network panel.
Is there anyway to make chrome add them to the sources panel?
Or how do you guys go about debugging dynamically added scripts?
Using Canary.
I was having the same problem, and I found a workaround that is better than the deliberate exception. It does still require changing the code as opposed to just setting a breakpoint inside the chrome dev tools.
I tried using the "//# sourceURL=dynamicScript.js" that was suggested as a workaround by the OP, but it still wasn't showing up for me unless it already existed in my tabs from a previous time when it produced an exception.
Coding a "debugger;" line forced it to break at that location. Then once it was in my tabs in the Sources panel, I could set breakpoints like normal and remove the "debugger;" line.
Please refer to https://developer.chrome.com/devtools/docs/javascript-debugging#breakpoints-dynamic-javascript
(Original link is broken-- archived link below)
http://web.archive.org/web/20141016164821/https://developer.chrome.com/devtools/docs/javascript-debugging#breakpoints-dynamic-javascript ("Breakpoints in Dynamic JavaScript").

Scala Lift - Robust method to protect files from hotlinking

I'm attempting to implement a way to stop hotlinking and/or un-authorised access to resources within my app.
The method I'm trying to add is something I've used before in PHP apps. Basically a session is set when the page is first called. The images are added to the page via the image tag with the session value as a parameter:
<img src="/files/image/image1.jpg?session=12345" />
When the image is requested the script checks to see if the session is set and matches the provided value. If the condition is not met the serving page returns null. Right at the end to the code I unset the session so further requests from outside the scope of the page will return null.
What would be the best implementation of this method within the lift framework?
Thanks in advance for any help, much appreciated :)
You could use a SessionVar for this purpose. In the SessionVar you’d store a Map[SessionImageId, RealImageId] and upon initialising the Session (i.e. when the page is first loaded) you’d generate some random SessionImageIds which you would map to the real image id. In your html you only expose the shadowed SessionImageId so no-one could trace back the image from the id. When the image is requested, you’d simply look up the real id in the Map.
Info: Exploring Lift, Lift wiki
Of course, if shadowing the ids is not important, you could simply use a SessionVar[Boolean].

Working with Facebook Connect

I have two files with identical code (it is the code they mention here: http://developers.facebook.com/blog/post/198). I have one of these files here: http://gnucom.cc/test.html and another one of these files here: http://blog.gnucom.cc/test.html. I have the main URL set to gnucom.cc and the Connect URL set to http://blog.gnucom.cc.
For the life of me, I cannot figure out why the version accessed from the subdomain doesn't work. I receive a loading icon and that is it - afterwards it disappears.
Can anyone suggest what I may be doing wrong?
http://wiki.developers.facebook.com/index.php/Supporting_Subdomains_In_Facebook_Connect
You should type in http://gnucom.cc instead of http://www.gnucom.cc (if it's not already this way)