How to duplicate liferay portlet - java

I have a custom portlet that I added to Liferay. I am looking for a way to duplicate the portlet, make some very little changes on it and use it on another community i.e. I want to be able to see the two portlets when I login as super admin and click on the add application link. Does anyone know an easy way of doing this?

You can define any number of portlets in portlet.xml - so if there's currently only one, you can add another one, implement (through copy/paste, inheritance or delegation, just as you like) the functionality needed. If you take a look at the liferay-specific deployment descriptors also in WEB-INF/, you can provide more information about your modified portlet there as well.

If a portlet needs to be duplicated with only small changes, maybe you can look at portlet preferences as well. This way, you can add multiple instances of the same portlet on one or more pages, and configuring their behavior at runtime. No need to duplicate the portlet project or to define multiple portlets in your portlet.xml.
For more information about portlet preferences, check the Portlet API JavaDocs.

I don't thing this is possible, in that case you need to create a new portlet copying all content from the old one and modify it.

Related

how to redirect from jsp of one portlet to jsp of another portlet inside liferay module project in liferay 7

I have created two liferay module project. one is "portlet-demo1" and second is "portlet-demo2"
Now I need to navigate from view.jsp of "portlet-demo1" to view.jsp of "portlet-demo2"
NOTE : Here both portlet is in separate page.
Now I need to navigate from one portlet jsp to another portlet jsp file.
how to do this using liferay 7.
If you separate the two portlets into two different modules, you should treat the JSPs of the other module as an implementation detail, e.g. you can't reach it (even if there'd be a way to reach them).
If the two portlets are tightly coupled and should share their implementation details, you can easily deploy them as a single module. This signals to anybody maintaining them, that they're required to be deployed together. Otherwise you might end up with one portlet being incomplete because the other portlet updated and nobody was aware that a JSP was used by some external component.
It's no problem to package two portlets in a single module. Go with that technique.

Is There a Glossary for each Liferay JSP?

Asked on Liferay Forums - post
I'm creating a Hook on top of Liferay's Doucment and Media Portlet to extend the original JSP. Extending the JSPs are straightforward, but I have no idea what they might be called. Sure I can guess but who wants to do that? In particular, I want to add an additional menu item on Document and Media's > Document > Edit Dropdown Menu
Does Liferay provide a glossary or index on where I could find this and any other JSPs I might extend?
Simple answer: No.
While JSPs are easy to overload, there's no API involved and technically you're in the implementation and not the API. Thus there's no assumption about good maintainability, no promise for stability and no API-style documentation at all.
I'm aware that JSPs are popular to overload, but they're actually dangerous and must be used with care.
You will have to view source for this kind of modification. But as soon as you realize that you're hitting the implementation, it all makes sense (and you don't really want to overload them any more)
Here's an answer I got from another member on the forums:
Hey Clay,
There is no "glossary" per say (at least not one that I am aware of)
but once you understand the pattern that LR uses it can be pretty
straight forward. First things first, if you don't already have it in
place, make sure you download the source for the version of the portal
that you are using.
under the portal-web module you will find /html/portlet. This is where
all the views for the Liferay portlets are stored. Most of them are
pretty straight forward. For example, doucment_library in your case.
The other thing you want to look at is the struts-config.xml file
(portal-web/WEB-INF). In that file you can search for "documents" and
you will find all sorts of documents and media references. What you
are interested in, for example, is something like this I think --
1 <forward name="portlet.users_admin.edit_organizationpath="portlet.directory.view_organization" />
The "path" attributes are references to the jsp files. So in this
case, /html/portlet/directory/view_organization.jsp -- /html being
implicit for these paths. I often reference this file to understand
where the struts actions for things in the control panel go.
So, no "one pager" with all the details, but once you understand the
pattern (which is super basic) it's easy peasy to get around.
Hope this helps!

Overloading web content Portlet in Liferay

In Liferay, when you add a web content to a page, a Portlet is created and you can choose the web content that will be displayed (when logged as admin), and you can choose some parameters (rights to view the content, share...).
I would like to create a Portlet that overloads this Portlet, to allow the admin to choose his / her web content with custom parameters.
Does anyone know how this could be done ? Thanks !
First idea which came to my mind is to hook default Web Content
Display Portlet This would allow you to add some custom business
logic to this portlet and not need to implement all you already get
from original one. Still this will much depends on how much your new
features you want to add, are complex.
As you have said, you are beginner, so here are some hints, how to start up with hook creation:
Visit https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/liferay-plugin-types-to-develop-with-maven section Developing Liferay Hook Plugins with Maven This archetype will create for you default structure of hook plugin.
Next step, is to download your liferay sources (if you haven't already) Visit official site https://www.liferay.com/downloads/liferay-portal/available-releases
Now when you have your sources, get these .jsp files which you want to modify, and copy to your hook. Make sure to keep folder structure as in default one.
Add your custom logic, in specified place and after deploying, test it.
Good luck
Another idea is to use maven war overlay which you can read
about more under http://java.dzone.com/articles/mavens-war-overlay-what-are
As you say you're a beginner, I'd suggest to create your own portlet that is independent of Liferay's portlets. You can use Liferay's API to get the article you'd like and its content, while implementing your own functionality to filter out the content you like.
The reason I'm suggesting a custom portlet is: Liferay's portlets must be as generic as possible, to match as many usecases as possible. Thus there are lots of conditionals that you won't need (and won't need to understand) in the implementation. If you have some narrow non-generic requirements to have an alternative behavior, you're easier off implementing exactly those requirements rather than adding to the generic, highly conditional UI. Plus, you might want to keep the original UI for other purposes. If you make a mistake in your own implementation, the original Web Content Display Portlet would still continue to work.
That being said, you might also look at the AssetPublisher portlet. It's the swiss army knife of content management and might already do what you want (and a lot more). This takes criteria and will evaluate them at runtime, displaying matching articles (or other content types).

How to pack portlet+theme+layout into single WAR/web application in Liferay?

The ROOT application contains all of the items described (classic theme, approx 10 layouts and numerous portlets).
Is it possible or good practice to create own packages like this? How to?
Please, give a hint.
Theoretically it is possible to have a single project with a Portlet, Theme, Layout and a Hook all packed in one.
But it is not at all a good-practice to have all the four types togather, from both maintenance and development perspective.
Though sometimes you may have a portlet and hook in one project if they are somehow related for example like you want to have some Listeners to add data to your custom table and then your portlet would provide an interface to update or view that data, so in this case they are interdependent and if the portlet goes the hook is of no use. So go ahead and combine them.
So if the 4 types are related somehow or interdependent than I see a usecase to have them togather (it would be rare) but still from maintenance point of view I would rather keep the 4 separate. Atleast I would keep portlets and themes separate and may have a Portlet-hook combination and a theme-layout combination since they go well with each other even from the maintenance & development point-of-view.
Here is how you can do it
Let the name of the project be say MyCompletePackage-portlet
The project can live in the portlets folder of the plugins-sdk if you are using the plugins-sdk.
Now add the plugin-type specific stuff as you normally do, like:
liferay-hook.xml for hooks
liferay-portlet.xml for portlets
liferay-look-and-feel.xml for themes
liferay-layout-templates.xml for layouts
For hook and portlet combination you won't need to modify the build.xml file and just build as you normally do.
Even for theme and layout combination you won't need to modify the build.xml.
But for theme and portlet combination you would need to include theme specific stuff in your build.xml.
Since the deployer looks for the specific files in the project it would know what all things you are deploying and would register them accordingly.
Let me know if this works for you or if you face any issues.
Disclaimer: I have not tried the 6th point but it should work
Generally one would add all portlets in one war so that they can access the service without any problems and to save context reloading time.
However Themes with portlets might not be a good idea always since we change theme.. and thus while updating portlets reloading in unnecessary. Well that's once in months but still a statement to keep portlets away from themes war.

Liferay Nested portlet

Can I create my own nested portlet? i need to have a nested portlet, in which to add three custom portlets. Those three portlets should be added from code.
Can you do it? Yes. Should you do it? Well...
Consider using standard Layout templates - these are extremely quick to create.
For populating a page with content/portlets, I'm typically pointing to the sourcecode for sevencogs-hook (which was delivered up to Liferay 6.1.0 CE but is still valuable documentation for placing portlets on a page - among other things). Others might point you to dynamically adding portlets to a page.
If you have a limited amount of variations of portlets that you'd like to add to the page/nested portlet, consider adding all of them but selectively not displaying any content (e.g. use inter-portlet-communication) - this makes it more obvious to the random page administrator (who might be someone else than you) which content will be displayed where. Also, it gives you flexibility if you want to rearrange the output.
Picking up my first paragraph - just look at the source code for the core nested-portlet to figure out the mechanics to dynamically dispatch to embedded portlets if you can't think of solving the problem in any of the alternative ways that I've suggested. If you can't figure it out (or if the "how" was your original question") please edit your question and clarify what the actual question is - I have the feeling that you're not interested in a yes/no answer.

Categories

Resources