Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jordi Vallés
Programmatically adding a Custom portlet on a layout
January 23, 2011 11:44 AM
Answer

Jordi Vallés

Rank: New Member

Posts: 9

Join Date: October 17, 2010

Recent Posts

I am trying to programmatically add a custom portlet to a layout.

I've tried the example from the wiki, and it works fine. The layout and the porlet are created and can be displayed.

The problem arises when I try to do the same with a custom portlet I've created with Liferay IDE. The page creation and insertion of the portlet seems to go OK, but when I try to access the page on the portal, I get an error on my browser:


Internal Server Error

An error occurred while accessing the requested resource.


And on the server log, I get the following:
119:37:22,279 INFO  [PortalImpl:3812] Current URL /web/mcfoie/recipe-19 generates exception: org.apache.jasper.JasperException: javax.servlet.ServletException: com.liferay.portal.NoSuchResourceActionException: McRecipeController#ADD_TO_PAGE
219:37:25,241 ERROR [jsp:?] org.apache.jasper.JasperException: org.apache.jasper.JasperException: javax.servlet.ServletException: com.liferay.portal.NoSuchResourceActionException: McRecipeController#ADD_TO_PAGE
3org.apache.jasper.JasperException: org.apache.jasper.JasperException: javax.servlet.ServletException: com.liferay.portal.NoSuchResourceActionException: McRecipeController#ADD_TO_PAGE
4(continues...)


I've defined the corresponding resource-action ADD_TO_PAGE for my portlet, but to no avail...

Has anyone got a solution for that? This functionallity is mandatory on my application, so I would need a fix for it...

Thanks in advance
Jordi Vallés
RE: Programmatically adding a Custom portlet on a layout
January 27, 2011 10:59 PM
Answer

Jordi Vallés

Rank: New Member

Posts: 9

Join Date: October 17, 2010

Recent Posts

Hi,

I've been checking for similar problems reported and I've found a similar one on issue LPS-5645.

Here go my questions:
  1. Is it the same problem?
  2. If so, how do I apply this solution?


Thanks in advance,

Jordi
Jordi Vallés
RE: Programmatically adding a Custom portlet on a layout
February 8, 2011 6:45 AM
Answer

Jordi Vallés

Rank: New Member

Posts: 9

Join Date: October 17, 2010

Recent Posts

Does anyone have any clue on how to fix this?

Should I post an issue?

Thanks

Jordi
Minhchau Dang
RE: Programmatically adding a Custom portlet on a layout
February 9, 2011 8:48 PM
Answer

Minhchau Dang

LIFERAY STAFF

Rank: Expert

Posts: 349

Join Date: October 22, 2007

Recent Posts

Jordi Vallés:
Does anyone have any clue on how to fix this?

Looking at the exception, my best guess is that if it's a custom portlet, you (usually) need to add _WAR_foldernamewithnospacesordashes to the end of the portletId.
Jordi Vallés
RE: Programmatically adding a Custom portlet on a layout
February 10, 2011 6:26 AM
Answer

Jordi Vallés

Rank: New Member

Posts: 9

Join Date: October 17, 2010

Recent Posts

Thanks Minhchau, I'll give it a try.

Jordi
Jordi Vallés
RE: Programmatically adding a Custom portlet on a layout
February 10, 2011 10:40 PM
Answer

Jordi Vallés

Rank: New Member

Posts: 9

Join Date: October 17, 2010

Recent Posts

Minhchau Dang:
Jordi Vallés:
Does anyone have any clue on how to fix this?

Looking at the exception, my best guess is that if it's a custom portlet, you (usually) need to add _WAR_foldernamewithnospacesordashes to the end of the portletId.


I've done it and it doesn't work... Any other ideas?

My code looks like:
1String recipePortletId = layoutTypePortlet.addPortletId(userId,
2                "McRecipeController_WAR_mcrecipeportlet", "column-2", -1);


Thanks

Jordi
gofri _
RE: Programmatically adding a Custom portlet on a layout
February 11, 2011 1:17 AM
Answer

gofri _

Rank: Junior Member

Posts: 92

Join Date: March 2, 2007

Recent Posts

Any other ideas?


Try to skip permission checking:
1String recipePortletId = layoutTypePortlet.addPortletId(userId, "McRecipeController_WAR_mcrecipeportlet", "column-2", -1, [b]false[/b]);
Jordi Vallés
RE: Programmatically adding a Custom portlet on a layout
February 11, 2011 7:41 AM
Answer

Jordi Vallés

Rank: New Member

Posts: 9

Join Date: October 17, 2010

Recent Posts

gofri _:
Any other ideas?


Try to skip permission checking:
1String recipePortletId = layoutTypePortlet.addPortletId(userId, "McRecipeController_WAR_mcrecipeportlet", "column-2", -1, [b]false[/b]);


Nothing... I've even been changing the permissions, but it doesn't work...
Olaf Kock
RE: Programmatically adding a Custom portlet on a layout
February 11, 2011 8:33 AM
Answer

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 3570

Join Date: September 23, 2008

Recent Posts

Is your portlet instanceable? If so, you also need to add _INSTANCE_honk to its ID (replace honk by random 4 alphanumeric characters).

Do:
  • manually add your portlet to a page
  • go to "Look and Feel"
  • Advanced Styling
  • and add a css rule for your portlet


There you'll see the ID for your portlet - if there's a _INSTANCE_rand, you need that as well. You can make up the random part (and you should)
Jordi Vallés
RE: Programmatically adding a Custom portlet on a layout
February 11, 2011 11:04 PM
Answer

Jordi Vallés

Rank: New Member

Posts: 9

Join Date: October 17, 2010

Recent Posts

Thanks Olaf, it works!
Nitesh Kr Sahay
RE: Programmatically adding a Custom portlet on a layout
January 19, 2012 12:36 AM
Answer

Nitesh Kr Sahay

Rank: Junior Member

Posts: 58

Join Date: November 28, 2011

Recent Posts

I' ve created a jsf portlet and i want to add this portlet to a layout....programmatically .. can any one help please response ASAP
Nitesh Kr Sahay
RE: Programmatically adding a Custom portlet on a layout
January 19, 2012 12:58 AM
Answer

Nitesh Kr Sahay

Rank: Junior Member

Posts: 58

Join Date: November 28, 2011

Recent Posts

I' ve used a method addPortletId(grid,portletid,column) .... where portletid is the id of my own jsf portlet ......
but it thorw an exception... NoSuchResourceActionException ..... what should i do to overcome this problem...
Nitesh Kr Sahay
RE: Programmatically adding a Custom portlet on a layout
January 19, 2012 10:46 PM
Answer

Nitesh Kr Sahay

Rank: Junior Member

Posts: 58

Join Date: November 28, 2011

Recent Posts

I found the solution.... i have just follow the 7cogs hook ....