You are currently browsing the tag archive for the ‘liferay’ tag.

If set parameter target to _blank of the following lefary tag:

<liferay-ui:icon image=""  label=""  target="_blank"  message=""  url=""/>

It just shows “Opens New Window” beside the link text but not open link page in new tab.

If you look source of taglib/ui/icon/page.jsp you will see

<aui:a href="<%= url %>" id="<%= id %>" lang="<%= lang %>" target="<%= target %>">

<%= linkContent %>

</aui:a>

It creates link using aui:a tag here I found if I remove id parameter it woks fine. I mean if I make it like bellow:

<aui:a href="<%= url %>" lang="<%= lang %>" target="<%= target %>">

<%= linkContent %>

</aui:a>

It opens link page in new tab if target parameter set to _blank of liferay-ui:icon otherwise it opens on same window though target parameter is set to _blank.

Liferay provides “LocalServiceUtil” to interact with database, we can do the common and basic functionality using these LocalServiceUtil classes. However sometimes we may need to run complex quires beside the common service like filtering out from result list or directly getting the data by certain criteria etc. Liferay provides several factory classes in this case to make our life easier, listed bellow:

DynamicQueryFactoryUtil
OrderFactoryUtil
ProjectionFactoryUtil
PropertyFactoryUtil
RestrictionsFactoryUtil

Here I will provide a example on how to use DynamicqueryFactoryUtil to make dynamic query.

ClassLoader cl = PortalClassLoaderUtil.getClassLoader();
DynamicQuery dqi = DynamicQueryFactoryUtil.forClass(
AnnouncementsEntry.class, cl);


Criterion crit = PropertyFactoryUtil.forName("title").eq(title);
dqi.add(crit);


crit = PropertyFactoryUtil.forName("displayDate").eq(displayDate);
dqi.add(crit);

try {
results = AnnouncementsEntryLocalServiceUtil.dynamicQuery(dqi);

} catch (SystemException e) {
e.printStackTrace();
}

classloader ensure that the implementation class can be loaded . Propertyfactoryutil may used for checking certain feature like equality, between, empty, nonempty etc ie. Projection/ restriction. Actually PropertyFactoryUtil return a Property instance that allows us to create Criterion objects and to assign them in DynamicQuery.
Reference Link

Load user specific preference:

com.liferay.portal.model.Layout layout = ((com.liferay.portal.theme.ThemeDisplay)themeDisplay).getLayout();
javax.portlet.PortletPreferences portletSetup = com.liferay.portlet.PortletPreferencesFactoryUtil
.getLayoutPortletSetup(layout, "portlet_id");


try {
portletSetup.setValue("key", "value");
portletSetup.getValue("key", "default value");
} catch (ReadOnlyException e1) {
e1.printStackTrace();
}

here themeDisplay is user specific themeDispaly as a result it load user specific preference.

Load global preference:

javax.portlet.PortletPreferences portletSetup = actionRequest.getPreferences();


try {
portletSetup.setValue("key", "value");
portletSetup.getValue("key", "default value");
} catch (ReadOnlyException e1) {
e1.printStackTrace();
}

here actionRequest may be javax.portlet.RenderRequest or javax.portlet.ActionRequest or javax.portlet.PortletRequest

You need to set the following properties in liferay-portlet.xml or in case of overridden in ext liferay-portlet-ext.xml, if want to set company wise/ global preference for portlet:

<preferences-company-wide>true</preferences-company-wide>
<preferences-unique-per-layout>false</preferences-unique-per-layout>

If this type of error comes in development; actually I got this exception in liferay development and by googling found this occur for lucene storage error. So first what I have done: changed the lucene.store.type=file to lucene.store.type=jdbc in portal.properties. You may override it in portal-ext.properties of ext without modifying directly in liferay code.

After that exception may throw like bellows:

Check Lucene directory failed for 0
java.lang.NullPointerException
at org.apache.lucene.store.jdbc.support.JdbcTable.setName(JdbcTable.java:183)
at org.apache.lucene.store.jdbc.support.JdbcTable.<init>(JdbcTable.java:75)
at org.apache.lucene.store.jdbc.support.JdbcTable.<init>(JdbcTable.java:69)
at org.apache.lucene.store.jdbc.JdbcDirectory.<init>(JdbcDirectory.java:121)
at com.liferay.portal.search.lucene.IndexAccessorImpl._getLuceneDirJdbc(IndexAccessorImpl.java:318)
at com.liferay.portal.search.lucene.IndexAccessorImpl.getLuceneDir(IndexAccessorImpl.java:161)
at com.liferay.portal.search.lucene.IndexAccessorImpl._checkLuceneDir(IndexAccessorImpl.java:188)
at com.liferay.portal.search.lucene.IndexAccessorImpl.<init>(IndexAccessorImpl.java:77)
at com.liferay.portal.search.lucene.LuceneHelperImpl._getIndexAccessor(LuceneHelperImpl.java:287)
at com.liferay.portal.search.lucene.LuceneHelperImpl.deleteDocuments(LuceneHelperImpl.java:168)
at com.liferay.portal.search.lucene.LuceneHelperUtil.deleteDocuments(LuceneHelperUtil.java:165)
at com.liferay.portal.search.lucene.LuceneIndexWriterImpl.deletePortletDocuments(LuceneIndexWriterImpl.java:85)
at com.liferay.portal.kernel.search.messaging.SearchWriterMessageListener.doReceive(SearchWriterMessageListener.java:75)
at com.liferay.portal.kernel.search.messaging.SearchWriterMessageListener.receive(SearchWriterMessageListener.java:41)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:73)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:68)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)

Here you need to change little in database connection URL:

jdbc.default.url=jdbc:mysql://localhost/DBName?emulateLocators=true&useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false

Added emulateLocators=true in database URL; Also don’t forget to clean database. now running ok for me 🙂

If error comes like bellow:

org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
at org.apache.lucene.store.Lock.obtain(Lock.java:70)
at org.apache.lucene.index.IndexWriter.init(IndexWriter.java:598)
at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:410)
at com.liferay.portal.lucene.IndexWriterFactory.getWriter(IndexWriterFactory.java:182)
at com.liferay.portal.lucene.LuceneUtil.getWriter(LuceneUtil.java:285)
at com.liferay.portal.lucene.LuceneUtil.getWriter(LuceneUtil.java:279)
at com.liferay.portal.plugin.PluginPackageIndexer.addPluginPackage(PluginPackageIndexer.java:78)
at com.liferay.portal.plugin.PluginPackageIndexer.updatePluginPackage(PluginPackageIndexer.java:227)
at com.liferay.portal.plugin.PluginPackageUtil._indexPluginPackage(PluginPackageUtil.java:835)
at com.liferay.portal.plugin.PluginPackageUtil._parseRepositoryXml(PluginPackageUtil.java:987)
at com.liferay.portal.plugin.PluginPackageUtil._loadRepository(PluginPackageUtil.java:886)
at com.liferay.portal.plugin.PluginPackageUtil.reloadRepositories(PluginPackageUtil.java:612)
at com.liferay.portlet.admin.job.CheckRemoteRepositoriesJob.execute(CheckRemoteRepositoriesJob.java:47)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)

 

To solve this error delete your lucene directory, deploy all and restart server . Check your portal.properties or portal-ext.properties to figure out where this is, by default it is configured as:

lucene.dir=${liferay.home}/data/lucene/
liferay.home=${resource.repositories.root}
resource.repositories.root=${default.liferay.home}

May 2024
S M T W T F S
 1234
567891011
12131415161718
19202122232425
262728293031  

RSS Hima’s Blog

  • An error has occurred; the feed is probably down. Try again later.