11/24/2011

How to find out on which page your Web Content is displayed

Think about the following problem:


You created a WebContent and within one of your portlets you need to find out where this WebContent is displayed (using Journal Article Display portlets). Sadly, there is no convenience method for this, so we have to biuld our own. We will do this using dynamic queries.


First we are going to get all portlet preferences that have been saved by portlet "56" (which is the Journal Article Display Portlet) and contain the ID of the Web Content we are looking for. This is exactly what is written into the database if you are selecting a WebContent in the WebContent Display portlet. I haven´t found another way to get the info.


Once we have the portlet preferences, we use their "plid" property to get the layouts (= Liferay pages) the portlet is deployed on. And that´s it. You can for example use the friendly URL to navigate to that page.


//create query to retrieve Layouts

DynamicQuery layoutQuery = DynamicQueryFactoryUtil.forClass(Layout.class, PortalClassLoaderUtil.getClassLoader());

//create query to retrieve portlet preferences

DynamicQuery preferencesQuery = DynamicQueryFactoryUtil.forClass(PortletPreferences.class, PortalClassLoaderUtil.getClassLoader());

//tell preferences to look for instances of portlet "56" with the journalArticle in its preferences

preferencesQuery.add(RestrictionsFactoryUtil.like("portletid", "56 INSTANCE%"));
preferencesQuery.add(RestrictionsFactoryUtil.like("preferences", "%<name>article-id</name><value>"+journalArticleId+"</value>%"));
preferencesQuery.setProjection(ProjectionFactoryUtil.property("plid"));

//just return the layouts that have the plid set for the ones we retrieve in the preferences query

layoutQuery.add(PropertyFactoryUtil.forName("plid").in(preferencesQuery));

//get the data

List dynamicQuery = PasswordPolicyLocalServiceUtil.dynamicQuery(layoutQuery);



If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.

11/08/2011

Solr: Q.Op default value

Currently working with Solr. As you know, you can use Solr as primary search engine in your liferay environment. One thing that might be interesting to you is the fact what the Q.OP operator does. The Q.OP operator specifies the "connector" between your search terms. Possible values are AND and OR.

I took a look into google and found no entry for "q.op default value", so here it is: The default value is ... up to you ;)


You can specify it in your schema.xml file like this:



 <solrQueryParser defaultOperator="OR"/>


If you like this post it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.