portlet-liferay.xml: How to use portal-javascript-header correctly - liferay

I copied jquery.js to WebContent/js/jquery/jquery.js. Now I want to use that file in certain portlets. To do this I created a liferay-portlet.xml that looks like this:
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC
"-//Liferay//DTD Portlet Application 6.0.0//EN"
"http://www.liferay.com/dtd/liferay-portlet-app_6_0_0.dtd">
<liferay-portlet-app>
<portlet>
<portlet-name>MyPortletName</portlet-name>
<header-portal-javascript>/js/jquery/jquery.js</header-portal-javascript>
</portlet>
</liferay-portlet-app>
If I access the portlet Liferay generates this line:
<script src="/js/jquery/jquery.js?browserId=firefox&minifierType=js&languageId=en_US&b=6100&t=1326630657000" type="text/javascript"></script>
That leads to a WARN [404_jsp:?] /js/jquery/jquery.js in the logging console.
Is it really correct that the URL looks like this? If I had two war-files, both containing a js-file with the same path, how would Liferay distinguish those two?
What do I need to do to get my setup working?
Using Liferay Portal Community Edition 6.1.0 CE (Paton / Build 6100 / December 15, 2011)

Use
<header-portlet-javascript>/js/jquery/jquery.js</header-portlet-javascript>
isntead of
<header-portal-javascript>/js/jquery/jquery.js</header-portal-javascript>
if you put js-files in to portlet
Because regarding comments in DTD, header-portal-javascript sets the path of JavaScript relative to the portal's context path. And header-portlet-javascript sets the path of JavaScript relative to the portlet's context path.

The location for jQuery looks incorrect.
If you're bundling this with your own plugin named foobar-portlet the correct path would be (provided that you use the same liferay-portlet.xml):
foobar-portlet/docroot/js/jquery/jquery.js

Two things:
jQuery is bundled with Liferay 5, check the version of Liferay and which jQuery version it has bundled and see if this meets your needs. However I believe it's not in Liferay 6 or 6.1, but I could be wrong about that.
And:
If you want to have a JavaScript library available to all of your portlets you're better off adding it to the theme(s) that you use rather than the portlets. This way it will be globally accessible. The downside is that if you're distributing your portlet then you should make people aware of this dependency.
Otherwise if you just want it available to a small group of your portlets, then follow what RP said.
Here's some good reference on using jQuery with Liferay 6.

Related

Integrating third party Bootstrap CSS themes with Bootsfaces

I seem to have reached a conundrum in integrating this third party Bootstrap theme within bootsfaces. Currently what I'm trying to do is include the css/js files within the xhtml files, but that doesn't seem to display any styling or show any references to the css files when inspecting the page. Will I need to build bootsfaces from source? Any help would be greatly appreciated
Starting with BootsFaces 0.8.0, we (the BootsFaces team) have added full-blown theme support. This include the default theme, 16 Bootswatch themes which are included in the library, and arbitrary custom themes. Read the details on our showcase.
However, in earlier versions (i.e. BootsFaces 0.7.0 and below) it was a bit more difficult to get custom or third-party themes up and running. Therefore, I recommend updating to BootsFaces 0.8.x, if you're still using an older version.
Update Dec 6, 2015: Forget about my former answer. BootsFaces theming works a bit different than I thought. We've changed it in the soon-to-come BootsFaces 0.8.0, anyways. I'll update my answer as soon as I'll have worked out the details.
The default Bootstrap theme of BootsFaces is a simple file (bsf.css). If you don't activate it in the web.xml, BootsFaces runs without any theme. So your approach should work: simply add the CSS file to your XHTML page, and you're good to go. You don't have to compile BootsFaces from source.

How to resolve conflict between hooks modifying the same jsp?

We have downloaded the Notifications portlet from liferay which modifies the JSP:
html/portlet/dockbar/view_user_account.jspf
And we are also modifying this particular jspf in our hook.
Currently what we are doing is we are copying the code from notifications portlet in our custom hook and are deploying our custom hook at the end so that our changes are applied.
Or else we would need to remove the JSP hook from notifications portlet by modifying the notification portlet's source.
Are there any better ways to achieve this?
Thanks
Unfortunately you're stuck between a rock and a hard place. You'll need to modify one of the plugins to not contain the JSP. Liferay can handle each JSP to be overridden max once.
An alternative might be to "hack" your changes through JS DOM manipulation after the page is displayed. This makes maintenance harder, but eases daily business and updates.
The big problem with any workarounds that involve two plugins changing the same JSP is that order is not defined. Also, it can be destructive: After deploying and undeploying two plugins that modify the same JSP, the original JSP is gone :(
Deploying plugin A, then B, followed by undeployment of A will leave you with only plugin B deployed, but use A's version of the overridden JSP.

Adding facelet taglib to Adf application

In my Adf application I need to use a javascript component called ckeditor (http://ckeditor.com/). Ideally I would like to use it on a facelet page (not a jsp page). It seems like this can be achieved by using ck-jsf-editor (https://code.google.com/p/ck-jsf-editor/). The problem is that I can't figure out how to add this library/taglib to my Adf application.
Anyone knows the best way to do this?
In JDeveloper, you need to add the JAR that contains the JSF component to the project properties under the JSP tag libraries section.
If you are on JDeveloper 11.1.2 or 12c then your ADF application can already use facelets.

JSF redirect static resources to external host

I'm running jsf app on glassfish v3. Machine has poor internet connection, so my idea was to move static content (css files, web graphics, fonts etc) to external hosting (using apache). I use jsf 2.0 resources, so links are generated like /javax.faces.resource/screen.css.html?ln=css. Question is, how can I automagically redirect such resources to external machine? The ideal way would be change it in one place (maybe glassfish configuration?) rather than change every link in whole app. THanks
That's not possible with standard <h:outputStylesheet> and <h:outputScript> components as the resources are loaded straight from the webapp context (and the classpath). Just use plain vanilla <link rel="stylesheet" /> and <script></script> tags.
There was ever a spec change request for this: issue 598. While this is targeted on JSF 2.2, I don't think that this will be implemented seeing the low votes.

How to add jsf components to taglib programmatically

I was wondering if it's possible to add JSF components to the tag library programmatically?
I'm implementing a plug-in mechanism in our application. And now, if I create a JSF component in the plug-in, I need to change the components taglib xml file in the main application, which is not the goal.
I'd rather like to put a components taglib xml file inside a plug-in which is then handled by the main application. Is there any way to do that?
The reason why I'm asking this is the following:
In our application, we send secure messages through a web interface. The messages are created by filling out forms, which are, in most cases, generated. But some forms have special behavior and we don't want to release the whole application if a new 'special form' is implemented, so we decided to put these in plug-ins.
Thanks for any help.
Cheers,
Andreas

Resources