Forums

RSS RSS
Portlets embedded in theme Flat View
Threads
Hello!

I have been trying to add some portlets to my theme for a few days and I'm quite perplexed as to how it should work. The example that I have been using is the one found in the Jedi theme, namely the code that displays the award images.

One example is that I would like to put a jounal content article on each of my pages. By using the following code, I succeed in doing that:

$theme.runtime("56_INSTANCE_a123")

However if I try to set that the journal content should have no borders, nothing happens. The journal content will appear with a border. The code that I tried to use was the following:

$velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
$theme.runtime("56_INSTANCE_a123", "", $velocityPortletPreferences.toString())
$velocityPortletPreferences.reset()


Is this supported currently by Liferay? If yes, could you point me to place in the documentation where this is discussed?

There is another thing that is unclear to me. Firstly, using the $theme.runtime() method I display a portlet on my page without any customisation. Then I customise it as an administrator. And the thing I don't understand is that when I create a new page (set as a copy of the old one), the customisations are not copied to the new page and I have to set everything again. Despite that the instance Ids are the same for the portlets on the two pages. Is this supposed to work this way?

Thanks for any info.

Cheers.
Flag Flag
RE: Portlets embedded in theme
5/6/08 12:14 PM as a reply to Zoltan Gabriel.
Hello,

i have also spent some time with this till I got to the philosophy... But is is so, like You write - because the method runtime creates the new portlet in the current page. So, there is actually created a new record in the Db table having the portlet preferences for this page. Because every portlet can have different prefereces on every page, if You create the new page , the theme.runtime method just creates the new representation of the portlet on your new page - so it is also filled by the default settings.

It is also pretty problematic to change the article in the page to some another - because in the case You have already called the method theme.rutime for the first time, the portlet preferences are not stored - You must delete the portlet from the page and reinitialize it again. I make it in the following way:
 1
 2    #set ($locGroupAndArticleIdForChecking = "$locArticleGroupId" + "_" + "$locArticleId" + "_")
 3    $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
 4    $velocityPortletPreferences.setValue("group-id", "$locArticleGroupId")
 5    $velocityPortletPreferences.setValue("article-id", "$locArticleId")
 6    #set ($locPortletId = "56_INSTANCE_" + $globCounterOfThemeDynamicPortletId)
 7    #set ($globCounterOfThemeDynamicPortletId = $globCounterOfThemeDynamicPortletId + 1)
 8    #set($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
 9    #set ($locCorrectArticleHasBeenReturned = $locRenderedPortletContent.contains($locGroupAndArticleIdForChecking))
10    #if ($locCorrectArticleHasBeenReturned)
11        ##correct - let it be
12    #else
13        ##incorrect - the article or group Id has been changed - so remove the old porltet preferences record and reinitialize it:
14        #set ($locPortletPreferenceService = $serviceLocator.findService("com.liferay.portal.service.PortletPreferencesLocalService"))
15        #set ($locPlidLong = $getterUtil.getLong($plid))
16        $locPortletPreferenceService.deletePortletPreferences(0, 3, $locPlidLong, $locPortletId)
17        ##  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0 ... PortletKeys.PREFS_OWNER_ID_DEFAULT, 3 ... PortletKeys.PREFS_OWNER_TYPE_LAYOUT
18        #set ($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
19    #end
20    $locRenderedPortletContent
21    $velocityPortletPreferences.reset()


- in $locArticleGroupId and $locArticleId are the Ids of the group to which belongs the article and id of article I want to put ionto the theme and $globCounterOfThemeDynamicPortletId is the counter of the portlet to get always a unique Id of the portlet for the page (this is maybe not necessary). I use the fact the Id of the group and article assigned to $locGroupAndArticleIdForChecking is contained in the rendered portlet content of the rendered journal article content - so I first check if it is correct - this is in the case the article has not been changed to the article with another article id from the last time the page has been rendered. In the case the value from $locGroupAndArticleIdForChecking is not contained in the portlet content then the content previously pointed to some other article (with other article id), therefore I delete it by calling deletePortletPreferences and call the runtime method again to recreate the portlet content with the changed preferences.

It is necessary to the check for $locGroupAndArticleIdForChecking there, because otherwise to be sure the correct article is rendered, You would have always to delete the portelt preferences and create it again - this would be then the case with every rendering of every page - this would be very ineffective, so I added such a check there...

I hope this can help - if my description can be understood, what I am not very sure ;-)

with regards, Artur
Flag Flag
RE: Portlets embedded in theme
5/7/08 4:47 AM as a reply to Artur Linhart.
Hello,

Your reply was absolutely understandable emoticon.

With the code you supplied I managed to set the article id and also remove the borders of the journal content portlet. This also solved the new page problem.
What didn't work for me though was the use of the global id counter. But the whole thing worked also without that.

So thank you, your comment was very helpful.

Cheers,
Zoltan
Flag Flag
RE: Portlets embedded in theme
5/7/08 6:15 AM as a reply to Zoltan Gabriel.
Ok, it's good to hear it could help You... :-)

I forgot to mention the globalId has to be set to the value which has 4 numbers, so tit has to be initialized first by calling, for example

1
2#set ($globCounterOfThemeDynamicPortletId = 1000)


- I used it because I created the more universal theme and there have been more sections where could be defined the articles - so in this case this would be a problem because the portlet Id would be not unique on one page... And because the sections are created dynamically I cannot assign to the dynamically generated portlets some predefined Ids, but they have to be computed automatically...
The part I copied here to You is the part of one velocity "procedure" which is called on multiple places from the main velocity file with different parameters - and then the global Id contains the global variable for the portlet id generation.

with regards, Archie.
Flag Flag
RE: Portlets embedded in theme
5/8/08 7:01 AM as a reply to Artur Linhart.
It'd be nice if PwdGenerator was in the velocity vars to make this more "standard", since that is the util we use internally to generate instance ids...
Flag Flag
RE: Portlets embedded in theme
5/12/08 10:33 PM as a reply to Ray Augé.
Aha, interesting inforamtion. Does it also assure the uniqueness of the Id?
I suppose it has to be unique at least in the page, isn't it?
Flag Flag
RE: Portlets embedded in theme
5/13/08 1:33 PM as a reply to Artur Linhart.
Well, consider the scope of the uniqueness includes the plid and the portletId. So, it's extremely small chance that two exact same id's are generated.

To be honest, I've never actually done any testing or looked closely at the validation code to see how hard we're checking to make sure there aren't collisions. Extracting the portlet instance ids from the page for only portlets of the same type would be necessary for the validation.
Flag Flag
RE: Portlets embedded in theme
5/16/08 3:56 AM as a reply to Artur Linhart.
Artur, great code!!
Flag Flag
RE: Portlets embedded in theme
5/19/08 1:45 AM as a reply to Matteo Pini.
thank You :-) nice to hear this can help somebody :-)

cheers, Archie
Flag Flag
It'd be nice if PwdGenerator was in the velocity vars to make
this more "standard", since that is the util we use internally to
generate instance ids...


On Wed, 2008-05-07 at 13:15 +0000, Artur Linhart at Liferay's Community
Forums wrote:

> Ok, it's good to hear it could help You... :-)
>
> I forgot to mention the globalId has to be set to the value which has
> 4 numbers, so tit has to be initialized first by calling, for example
>
>
> 1
> 2#set ($globCounterOfThemeDynamicPortletId = 1000)
>
>
>
>
> - I used it because I created the more universal theme and there have
> been more sections where could be defined the articles - so in this
> case this would be a problem because the portlet Id would be not
> unique on one page... And because the sections are created dynamically
> I cannot assign to the dynamically generated portlets some predefined
> Ids, but they have to be computed automatically...
> The part I copied here to You is the part of one velocity "procedure"
> which is called on multiple places from the main velocity file with
> different parameters - and then the global Id contains the global
> variable for the portlet id generation.
>
> with regards, Archie.
> --
> Liferay Community Forum
> mb.239389.776959@events.liferay.com
> http://www.liferay.com/web/guest/community/forums/message_boards/message/776959

Raymond Augé
Software Engineer
Liferay, Inc.
Enterprise. Open Source. For Life.
Flag Flag
RE: Portlets embedded in theme
4/13/09 6:44 AM as a reply to Artur Linhart.
I am trying to add alerts portlet in theme in Liferay 5.1.4 EE and it is giving javascript error with the use of following code:

$velocityPortletPreferences.setValue("portlet-setup-show-borders", "true")
$theme.runtime("83", "", $velocityPortletPreferences.toString())
$velocityPortletPreferences.reset()


Becuase of below errors portlet is not working properly.
Errors are as below:

Error: c.submit is not a function
Source File: http://localhost:8080/html/js/barebone.jsp?browserId=firefox&themeId=dsi_1_WAR_dsi_1theme&colorSchemeId=01&minifierType=js&minifierBundleId=javascript.barebone.files&minifierBundleDir=%2Fhtml%2Fjs&t=1239595987031
Line: 1


Error: c is undefined
Source File: http://localhost:8080/html/js/barebone.jsp?browserId=firefox&themeId=dsi_1_WAR_dsi_1theme&colorSchemeId=01&minifierType=js&minifierBundleId=javascript.barebone.files&minifierBundleDir=%2Fhtml%2Fjs&t=1239595987031
Line: 1


Can anyone help me to resolve this issue?

Thanks in advance,
Tarun
Flag Flag
RE: Portlets embedded in theme
5/22/09 4:09 AM as a reply to Zoltan Gabriel.
Artur Linhart:

 1
 2    #set ($locGroupAndArticleIdForChecking = "$locArticleGroupId" + "_" + "$locArticleId" + "_")
 3    $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
 4    $velocityPortletPreferences.setValue("group-id", "$locArticleGroupId")
 5    $velocityPortletPreferences.setValue("article-id", "$locArticleId")
 6    #set ($locPortletId = "56_INSTANCE_" + $globCounterOfThemeDynamicPortletId)
 7    #set ($globCounterOfThemeDynamicPortletId = $globCounterOfThemeDynamicPortletId + 1)
 8    #set($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
 9    #set ($locCorrectArticleHasBeenReturned = $locRenderedPortletContent.contains($locGroupAndArticleIdForChecking))
10    #if ($locCorrectArticleHasBeenReturned)
11        ##correct - let it be
12    #else
13        ##incorrect - the article or group Id has been changed - so remove the old porltet preferences record and reinitialize it:
14        #set ($locPortletPreferenceService = $serviceLocator.findService("com.liferay.portal.service.PortletPreferencesLocalService"))
15        #set ($locPlidLong = $getterUtil.getLong($plid))
16        $locPortletPreferenceService.deletePortletPreferences(0, 3, $locPlidLong, $locPortletId)
17        ##  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0 ... PortletKeys.PREFS_OWNER_ID_DEFAULT, 3 ... PortletKeys.PREFS_OWNER_TYPE_LAYOUT
18        #set ($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
19    #end
20    $locRenderedPortletContent
21    $velocityPortletPreferences.reset()




Is it possible to have another example of this code in a simpler version? Like for the language or the search

I tried to change the code here but my skills on coding r not that good.

If anyone can provide an example it will be great.

Thanx

Edit: I tried to make it work for the search portlet but Instead of the search box I got this msg in the portlet on the page "
This portlet has been undeployed. Please redeploy it or remove it from the page. "

Can someone help?

------------------------------

EDIT 2:

Ok I managed to correct the previous problem but now I get the portlet 2 times in the page + "You do not have the roles required to access this portlet." alert.

In the log i got 2 warning

WARN [PortletRequestProcessor:471] The struts path language does not belong to portlet 82_INSTANCE_1000. Check the definition in liferay-portlet.xml

WARN [PortletRequestProcessor:507]

Please if anyone can help.

P.S. Where I can find a list of with all these variables, objects, methods etc? I followed some links but instead of helping it get more confusing that it is now and I still do not have a clear list.

For example the "$locRenderedPortletContent.contains". Is there something else?
Like $locRenderedPortletContent.notContains or $locRenderedPortletContent.head or something

Is this a variable that already exists? If yes where r the others?
Flag Flag
RE: Portlets embedded in theme
5/22/09 4:13 AM as a reply to Zoltan Gabriel.
BUMP
Flag Flag
RE: Portlets embedded in theme
5/25/09 5:34 AM as a reply to Zoltan Gabriel.
BUMP

6k views and noone can help?
Flag Flag
RE: Portlets embedded in theme
5/25/09 10:14 AM as a reply to Nikos Kapatos.
It always bothered me that a new database record would need to be created per page when using the $theme.runtime method of injecting a portlet.

Have you considered the following approach. Create a hidden page with your portlet on it. Then copy the "Sharing" javascipt injection code into your theme.

I haven't tried it, but it seems like it would work to me.

If you try it and it works, please let me know.

emoticon
Flag Flag
RE: Portlets embedded in theme
7/21/09 10:11 AM as a reply to atul patel.
This awful JS generates an iframe... This is hardly usable even to share with external websites, so I can't imagine using this for internal pages...
Flag Flag
RE: Portlets embedded in theme
11/18/09 6:30 AM as a reply to Zoltan Gabriel.
Artur Linhart:
 1
 2    #set ($locGroupAndArticleIdForChecking = "$locArticleGroupId" + "_" + "$locArticleId" + "_")
 3    $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
 4    $velocityPortletPreferences.setValue("group-id", "$locArticleGroupId")
 5    $velocityPortletPreferences.setValue("article-id", "$locArticleId")
 6    #set ($locPortletId = "56_INSTANCE_" + $globCounterOfThemeDynamicPortletId)
 7    #set ($globCounterOfThemeDynamicPortletId = $globCounterOfThemeDynamicPortletId + 1)
 8    #set($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
 9    #set ($locCorrectArticleHasBeenReturned = $locRenderedPortletContent.contains($locGroupAndArticleIdForChecking))
10    #if ($locCorrectArticleHasBeenReturned)
11        ##correct - let it be
12    #else
13        ##incorrect - the article or group Id has been changed - so remove the old porltet preferences record and reinitialize it:
14        #set ($locPortletPreferenceService = $serviceLocator.findService("com.liferay.portal.service.PortletPreferencesLocalService"))
15        #set ($locPlidLong = $getterUtil.getLong($plid))
16        $locPortletPreferenceService.deletePortletPreferences(0, 3, $locPlidLong, $locPortletId)
17        ##  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0 ... PortletKeys.PREFS_OWNER_ID_DEFAULT, 3 ... PortletKeys.PREFS_OWNER_TYPE_LAYOUT
18        #set ($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
19    #end
20    $locRenderedPortletContent
21    $velocityPortletPreferences.reset()


Hi guys,

can you tell me if that code works with liferay 5.2.2?

thanks and regards:
Flag Flag
RE: Portlets embedded in theme
12/16/09 12:52 PM as a reply to Artur Linhart.
Has anyone tested this for portlets deployed using plugins? I get a "This portlet has been undeployed" message for my custom portlet, but not for those defaulted in Liferay.
Flag Flag
RE: Portlets embedded in theme
1/25/10 3:14 AM as a reply to Artur Linhart.
Hello Artur,

I saw your post regarind portley placement on theme.
Very nicely you have explained.

I am new to liferay and want to develop my own theme, i created a new theme in SDK env.
then i want to change banner, logo etc. the look and feel of theme, i want to change it programmatically.

Also i want to put 4 portlet on theme, so that it will be visible to the end user.

and i want to know in wihch file you have written the code below in your post, for visibilty of portlets in the theme.

please help me in these query, its very urgent.

Thanks in advance.
I will be waiting for your reply.

Anj
Flag Flag
RE: Portlets embedded in theme
1/28/10 12:36 AM as a reply to anju a anjua.
portal_normal.vm would be a good place to start.
Flag Flag
RE: Portlets embedded in theme
2/9/10 11:54 PM as a reply to anju a anjua.
Hello,

atul patel is right, it is efectivelly called from portal_normal.vm.

Because I have more such article sections in one article, I have put it into some separate script, which is then parametrized from outside and included more times in portal_normal.vm

Sorry for the delay, I was now for longer time busy with other things and had therefore no time to look here regulary...

with regards, Artur
Flag Flag