Include js/css in Liferay DXP JSP Hook (module fragment) - liferay

I am working on Liferay DXP SP3 with fix pack 24 installed. I have created a module fragment project to override (hook) the edit_permissions JSP. I have CSS and Javascript that is very specific to this custom JSP so I would like to include it with the module rather than with the theme. Based on this documentation, it sounds like I should be able to do this by making the module a "theme contributor" module. I have set the Liferay-Theme-Contributor-Type and Web-ContextPath attributes in the bnd.bnd file, like this:
Liferay-Theme-Contributor-Type: portlet.config.jsp.overrides
Web-ContextPath: /edit-permissions-theme-contributor
I have created a /src/main/resources/META-INF/resources/js folder and placed my custom javascript files in this folder. It is my understanding that with this configuration I should be able to include the custom javascript files in my JSP hook using a regular script tag with a path like this:
<script type="text/javascript" src="/o/edit-permissions-theme-contributor/js/my-custom-script.js"></script>
I have tried many variations of the URL (with and without the "o", etc.). However, I always get a 404 on my script file. Am I doing this incorrectly? Is there a better way to include static files in a fragment module?

Related

Unable to load GLTF file in ASP.NET View implementing A-FRAME

One of the views (.cshtml file) of my ASP.NET MVC application is using A-Frame. I am trying to load a 3-D model using GLTF file inside the <a-scene> tag.
<body>
<a-scene>
<a-assets timeout="5000">
<a-asset-item id="tree" src="~/Assets/scene.gltf">
</a-assets>
<a-gltf-model src="#tree"></a-gltf-model>
</a-scene>
</body>
I have already tested the src path in the same page by putting a .png file and loading it in <img/>, it works. The problem is just with the .gltf file.
What is possibly wrong with the .gltf file in particular?
The URL doesn't seem like a valid URL. It seems like a Unix path. Host the GLTF somewhere the website can reach it (like the same directory) and fix the path. src="scene.gltf".

import js file to header all jsp in liferay

I'm going to import a js file to the header of all pages exist in liferay portal.
I know I have to do in Hook.I put import this js into init.jsp in ..\html\common , but was import to all elements of the liferay pages.
I don't know where put this file?
You don't have to do this in a hook. Do it in your theme as the theme is responsible for generating the whole document, including the <html> and <head> sections.
In the theme, override templates/portal_normal.vm. It should be obvious where to put the script reference.
You'll override this file by creating a docroot/_diffs/templates folder and copy docroot/templates/portal_normal.vm to that location. Then edit the file in docroot/_diffs/templates, build and deploy your theme.

How to run content script code on an HTML file locally hosted by Google Chrome Extension? [duplicate]

I want to run a content script on an iframe with a chrome-extension:// URL. I added a line to my manifest.json that I copied out of the documentation http://code.google.com/chrome/extensions/match_patterns.html
chrome-extension://*/*
But when I reload my extension I get an alert:
Could not load extension from '/work/sirius/extension'.
Invalid value for 'content_scripts[2].matches[0]': Invalid scheme.
Any idea how to get this to worK?
No. Only ftp:, file:, http: and https: can be matched by a content script declaration.
Invalid URL patterns at any of the matches and exclude_matches fields are rejected (generating an error when trying to load the extension).
Invalid patterns at the permissions option in the manifest file are ignored.
If you want to run a script on a tab from your extension, use chrome.extension.getViews in your background script.
Even better, design your extension's pages such that they effectively communicate with each other (example).
I'm having the exact same problem, look at the API http://code.google.com/chrome/extensions/match_patterns.html it says clearly that they accept chrome-extension://*/* yet they don't.
They need to update the API so as not to confuse people.
It seems that Chrome authors have silently removed the ability for content scripts to be injected into chrome-extension: pages. Documentation still says that it works and even contains examples with chrome-extension: scheme but actually it doesn't work. So now only http:, https: and ftp: work "from the box" and file: can work if user of your extension has enabled this on Extensions (chrome://extensions/) page.
Update: now documentation referred above is updated and says nothing about ability to inject content scripts to chrome-extension: pages.
You can inject js to your iframe html(chrome-extension: pages) without declaring it in manifast.json. The injected js can visit Chrome APIs directly.
iframe.html:
<!DOCTYPE html>
<html>
<head>
...
</head>
<body>
...
</body>
<script src="iframe.js"></script>
</html>
iframe.js:
console.log(chrome); // {loadTimes: ƒ, csi: ƒ, …}

include file directive not working in linux sever

My problem is, i have included a page using the code
<%#include file="../include/dbconnection.jsp"%>
My page resides in a sub directory of public_html but when i load my page it shows the following exception
org.apache.jasper.JasperException: /index.jsp(23,1) File "/../include/dbconnection.jsp" not found
But this code works fine in my development system(which is windows) i use a linux server for my website. Is this a problem with file separator or file permission issues? what could be the problem?
You can find your answer in the post below which is using <jsp:include page="..."> , the <%#include only works with static references.
Is it possible to have a dynamic path as part of a jsp include

How to get an image or js from a JAR in the server in JSF (For a custom component)

I have done a custom JSF component (it looks like a combobox (icefaces selectonemenu)) but it uses a couple of images (png) and a bit of javascript.
I jar everything, so then the developers use it as a jar copied in the web-inf/lib folder.
The image and the js are just for this custom component, so I can't make them put this image and js in his project, it has to be in MY jar.
I jar everything and it works almost great, just the image and the JS, I do not get them to work. I do not know how to reference them being in the jar. I could make them work as long as they are part of the application, but not being part of the jar.
How should I do to get them in my encodebegin code for example?
I am using JSF with icefaces 1.8
Thanks in advance!!
If you're already on JSF 2.0, it should work just fine out the box when you're using #ResourceDependency or #ResourceDependencies annotation which can resolve resources based on JAR's /META-INF/resources folder.
On JSF 1.x, your best bet is to create a custom "resource servlet" which is mapped on a certain URL pattern, e.g. /com.nahiko.resources/* and just streams the resources from the classpath to the HTTP response. Basic kickoff example:
String path = "/META-INF/resources" + request.getPathInfo();
InputStream input = getClass().getResourceAsStream(path);
OutputStream output = response.getOutputStream();
// ...
Document along your JAR that this servlet has to be mapped. Or if you target a Servlet 3.0 container, just add the #WebServlet annotation to get it to auto-register.

Resources