Forums de discussion

Two portlets inside of one liferay portlet project

thumbnail
Thiago Henrique Carvalho Prudente, modifié il y a 7 années.

Two portlets inside of one liferay portlet project

New Member Publications: 21 Date d'inscription: 15/06/15 Publications récentes
Good morning,

I created one Portlet class extending the MVCPortlet commonly, but I have many JSPs pages in my liferay project. I have just one render method so to manage many pages into just one method with many if and else conditions, isn't been a good practice of programming. The code started been confused because of many conditions in the render.

So I created other portlet classes extending the MVCPortlet to make my project cleaner, but I don't know how I could call the other renders, serveResources and actions methods of the other portlets, neither if it is possible. I saw in the add section of the admin role that exist my others portlets of the project, but I believe that just adding them isn't correct. I know that through the name of the portlet I would call the other portlets by URLs in the pages but I'm not sure how this URLs shoud be.

Please, could someone help me?
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Two portlets inside of one liferay portlet project

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
You can't. Different extensions of MVCPortlet are different portlet instances, they won't cross-call each other.

Your best path is to refactor your MVCPortlet to offload handling to separate classes, let the MVCPortlet instance manage the Controller part of MVC and it hands off to supporting instance classes to do the work.

That way you still stay within the vision of one portlet class yet have a modular and maintainable portlet.






Come meet me at the LSNA!
thumbnail
Thiago Henrique Carvalho Prudente, modifié il y a 7 années.

RE: Two portlets inside of one liferay portlet project

New Member Publications: 21 Date d'inscription: 15/06/15 Publications récentes
David H Nebinger:
to offload handling to separate classes


I didn't understand the above quote. could you give me one example or explain me please?
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Two portlets inside of one liferay portlet project

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
Well build a mechanism to dispatch handling. Define an interface such as RenderHandler, that has a method for processing the render. Then use a map of render keys to RenderHandler instances. In your portlet, you get the incoming render key, pull the handler from the map and let it do the work.

You refactor your logic so you don't have one huge class full of all of the knowledge for handling every single request you're dealing with.

This is a pretty simple (perhaps too simplistic) way of doing it, Spring (and others) have much more mature ways of dispatching that would be much better options.

In LR7, MVCPortlet framework takes advantage of more annotations to remove some of this manual dispatch handling, but you may be left to figuring out your own option if you're on an earlier version.





Come meet me at the LSNA!
thumbnail
Thiago Henrique Carvalho Prudente, modifié il y a 7 années.

RE: Two portlets inside of one liferay portlet project

New Member Publications: 21 Date d'inscription: 15/06/15 Publications récentes
thank you!