Friday, November 5, 2010

How to disable border for all Portlet?

liferay-look-and-feel.xml  (tomcat\webapps\ROOT\WEB-INF)

Add the following setting in liferay-look-and-feel.xml for disabling border for all portlets by default.


<theme id="classic" name="classic">
       <settings>
            <setting key="portlet-setup-show-borders-default" value="false" />
        </settings>
</theme>


  or

Portal-ext.properties (tomcat\webapps\ROOT\WEB-INF)

You can change it through property file also by adding this entry:

theme.portlet.decorate.default=false

- Gnaniyar Zubair

Web Service

Introduction

In general, web services are resources which may be called over the HTTP protocol to return data. They are platform-independent, allowing communication between applications on different operating systems and application servers. When the database entries are generated by ServiceBuilder, web services can be generated as well based on Apache Axis. As a result, nearly all of the backend API calls can be made using web services. Java clients may be generated from Web Service Definition Language (WSDL) using any number of tools (Axis, Xfire-CXF, JAX-RPC, and so on). Apache Axis is essentially a Simple Object Access Protocol (SOAP) engine—a framework for constructing SOAP processors such as clients, servers, gateways, and so on.
This document will show how to use the web services of liferay portal. Specially, it shows how to build web services and how manage organizations, users, User groups and roles.

Using Web services

When Liferay portal is up in your local machine, type the following URL in the browser. You will get a list of web services.
[http://127.0.0.1:8080/tunnel-web/axis]
[http://127.0.0.1:8080/tunnel-web/secure/axis]

What's happening?#

The portal uses Apache Axis to generate web services. The default Axis configuration is specified in the server-config.wsdd file under the /portal/tunnel-web/ docroot/WEB-INF folder. When you double-click on the target deploy in the Ant view, the file server-config.wsdd under the /portal/tunnel-web/docroot/WEBINF folder will be merged with the server-config.wsdd file under the /ext/extweb/ docroot/WEB-INF folder. Therefore, when you type http://127.0.0.1:8080/tunnel-web/axis in your browser, you will see a list of SOAP services.
To access a service remotely, the host must be allowed via the portal-ext. properties properties file. After that, the user must have permission to access the portal resources. The default settings to access a service remotely are specified in the portal.properties file as follows:
axis.servlet.hosts.allowed=127.0.0.1,SERVER_IP
axis.servlet.https.required=false
The code above shows the IPs to access the Axis servlet. You can input a blank list to allow any IP to access this servlet. SERVER_IP will be replaced with the IP of the host server. By default, 127.0.0.1 is the IP for local host. This is the reason that you can access web services only by the IP 127.0.0.1, and not localhost. Of course, you can use a domain name such as www.bookpub.com if you had set the mapping between 127.0.0.1 and www.bookpub.com in the hosts file.

Build custom WSDD #

Supposed the service.xml is at src/com/ext/portlet/reports of the folder $EXT_HOME/ext-impl. In order to build custom WSDD, we need to add the following lines after the lines
<target name="build-service-portlet-playerstats">
<antcall target="build-service">
<param name="service.file" value="src/com/xos/playerstats/portal/service.xml" />
</antcall>
</target>
in $EXT_HOME/ext-impl/build-parent.xml
<target name="build-wsdd-portlet-reports">
<antcall target="build-wsdd">
<param name="service.file" value="src/com/ext/portlet/reports/service.xml" />
</antcall>
</target>
And use the Ant Target "build-wsdd-portlet-reports" to generate WSDD files.

Add custom operations #

for example:
package com.ext.portlet.reports.service.impl;
import com.ext.portlet.reports.service.base.ReportsEntryServiceBaseImpl;
public class ReportsEntryServiceImpl extends ReportsEntryServiceBaseImpl {
public String LoadArticle () {
return "Test";
}
}
then build services and wsdd as:
ant build-service-portlet-reports
ant build-wsdd-portlet-reports

Build client #

Create a folder ext-client at $EXT_HOME
Add namespaceMapping.properties and build.xml at $EXT_HOME/ext-client
Add build-common-java.xml at $EXT_HOME
Type: ant build-client

namespaceMapping.properties #

com.my.client.soap.portlet.organization.model=[http://model.organization.portlet.my.com]
com.my.client.soap.portlet.organization.service.http=urn:http.service.organization.portlet.my.com

build.xml#

<?xml version="1.0"?>
<project name="ext-client" basedir="." default="compile">
 <import file="../build-common-java.xml" />
 <property name="jar.file" value="${ant.project.name}" />
 <property name="client.url" value="[http://localhost:8080/tunnel-web/axis"] />
 <target name="jar" depends="compile">
  <jar
   jarfile="${jar.file}.jar"
  >
   <fileset dir="classes" />
   <fileset dir="src" />
  </jar>
  <copy file="ext-client.jar" todir="${project.dir}/ext-lib/development" />
 </target>
 <target name="build-client" depends="clean">
  <echo message="Make sure the server is listening on ${client.url}." />
  <echo message="" />
  <delete dir="src" />
  <mkdir dir="src" />
  <java
   classname="com.liferay.portal.tools.PortalClientBuilder"
   classpathref="project.classpath"
   failonerror="true"
   fork="true"
   newenvironment="true"
  >
   <arg value="${project.dir}/ext-web/docroot/WEB-INF/server-config.wsdd" />
   <arg value="src" />
   <arg value="namespaceMapping.properties" />
   <arg value="${client.url}" />
  </java>
  <antcall target="jar" />
 </target>
</project>

build-common-java.xml#

<?xml version="1.0"?>

<project name="build-common-java" xmlns:antelope="antlib:ise.antelope.tasks">
 <import file="build-common.xml" />

 <if>
  <and>
   <equals arg1="${app.server.type}" arg2="tomcat" />
   <antelope:endswith string="${app.server.portal.dir}" with="/portal-web/docroot" />
  </and>
  <then>
   <property name="portal-impl.classes.dir" value="${project.dir}/portal-web/docroot/WEB-INF/classes" />
  </then>
  <else>
   <property name="portal-impl.classes.dir" value="${project.dir}/portal-impl/classes" />
  </else>
 </if>

 <target name="clean">
  <delete dir="classes" />
  <delete dir="test-classes" />
  <delete dir="test-results" />
  <delete file="${jar.file}.jar" failonerror="false" />
  <delete dir="${java2html.dir}" />
  <delete dir="${javadoc.dir}" />
 </target>

 <target name="compile">
  <mkdir dir="classes" />

  <copy todir="classes">
   <fileset dir="src" excludes="**/*.java" />
  </copy>

  <if>
   <equals arg1="${javac.compiler}" arg2="modern" />
   <then>
    <javac
     classpathref="project.classpath"
     compiler="${javac.compiler}"
     debug="${javac.debug}"
     deprecation="${javac.deprecation}"
     destdir="classes"
     fork="${javac.fork}"
     memoryMaximumSize="${javac.memoryMaximumSize}"
     nowarn="${javac.nowarn}"
     srcdir="src"
    />
   </then>
   <else>
    <javac
     classpathref="project.classpath"
     compiler="${javac.compiler}"
     debug="${javac.debug}"
     deprecation="${javac.deprecation}"
     destdir="classes"
     nowarn="${javac.nowarn}"
     srcdir="src"
    />
   </else>
  </if>
 </target>

 <target name="jar" depends="compile">
  <jar
   basedir="classes"
   jarfile="${jar.file}.jar"
  />
 </target>

 <target name="java2html">
  <java
   classname="j2h"
   classpathref="project.classpath"
   fork="true"
  >
   <arg line="-d ${java2html.dir} -js src -m 4" />
  </java>

  <replace dir="${java2html.dir}">
   <replacefilter
    token="stylesheet.css"
    value="java2html.css"
   />
  </replace>

  <move file="${java2html.dir}/stylesheet.css" tofile="${java2html.dir}/java2html.css" />

  <antcall target="javadoc" />

  <replace dir="${java2html.dir}">
   <include name="**/package-summary.html" />
   <replacefilter
    token="/\"
    value="/"
   />
  </replace>
 </target>

 <target name="javadoc">
  <mkdir dir="${javadoc.dir}" />

  <javadoc
   breakiterator="yes"
   classpathref="project.classpath"
   destdir="${javadoc.dir}"
   maxmemory="256m"
   packagenames="*.*"
   sourcepath="src"
   stylesheetfile="${project.dir}/tools/javadoc.css"
  />
 </target>

 <target name="deploy" depends="jar">
  <copy file="${jar.file}.jar" todir="${deploy.dir}" />
 </target>
</project>

CRUD on Organizations #

Simple code for Organization:
import java.net.URL;
import com.liferay.client.soap.portal.model.CompanySoap;
import com.liferay.client.soap.portal.model.OrganizationSoap;
import com.liferay.client.soap.portal.service.ServiceContext;
import com.liferay.client.soap.portal.service.http.CompanyServiceSoap;
import com.liferay.client.soap.portal.service.http.CompanyServiceSoapServiceLocator;
import com.liferay.client.soap.portal.service.http.OrganizationServiceSoap;
import com.liferay.client.soap.portal.service.http.OrganizationServiceSoapServiceLocator;
import com.liferay.client.soap.portal.service.http.UserServiceSoap;
import com.liferay.client.soap.portal.service.http.UserServiceSoapServiceLocator;
public class WSTest { 
 public static void main(String[] args) {
  // reference sql.data.com.liferay.portal.model.ListType.organization.status=12017
  try {
  String remoteUser = "test";
  String password = "test";
  String serviceOrgName = "Portal_OrganizationService";
  String serviceUserName = "Portal_UserService";
  String serviceCompanyName = "Portal_CompanyService";
  String virtualHost = "localhost"; 
  int statusId = 12017;
  long regionId = 0;
  long countryId = 0;
  long parentOrgId = 0;
  boolean recursable = true;  
  CompanyServiceSoapServiceLocator locatorCompany = new CompanyServiceSoapServiceLocator();
  CompanyServiceSoap soapCompany = locatorCompany.getPortal_CompanyService(
                       _getURL(remoteUser, password, serviceCompanyName));
  CompanySoap companySoap = soapCompany.getCompanyByVirtualHost(virtualHost);  
  UserServiceSoapServiceLocator locatorUser = new UserServiceSoapServiceLocator();
  UserServiceSoap soapUser = locatorUser.getPortal_UserService(_getURL(remoteUser, password, serviceUserName));
  long userId = soapUser.getUserIdByScreenName(companySoap.getCompanyId(), remoteUser);  
  OrganizationServiceSoapServiceLocator locator = new OrganizationServiceSoapServiceLocator();
  OrganizationServiceSoap soap = locator.getPortal_OrganizationService(_getURL(remoteUser, password, serviceOrgName));
  OrganizationSoap[] organizations = soap.getUserOrganizations(userId);
  for (int i = 0; i < organizations.length; i++) {
      OrganizationSoap organization = organizations[i];
      System.out.println(organization.getStatusId()+ "\t" + 
                                     organization.getOrganizationId() + "\t" + organization.getName() + "\t" + organization.getType());
  }
  // ServiceContext scxt = new ServiceContext();
  // OrganizationSoap org = soap.addOrganization(parentOrgId, "testOrg-MyOrg_Admin", 
                      //"regular-organization", recursable, regionId, countryId, statusId, "My Comments", scxt);
  // long users[] = {userId};
  // soapUser.addOrganizationUsers(org.getOrganizationId(), users);
  // soap.deleteOrganization(10232);
  }

  catch (Exception e) {
  e.printStackTrace();}
  }
  // Get URL
  private static URL _getURL(String remoteUser, String password, String serviceName) throws Exception {
  // Unathenticated url
  String url = "[http://127.0.0.1:8080/tunnel-web/axis/"] + serviceName;
  // Authenticated url
  if (true) {
  url = "[http://"] + remoteUser + ":" + password + "@127.0.0.1:8080/tunnel-web/secure/axis/" + serviceName;
  }
  return new URL(url);
  }
}
Note that
1) "sql.data.com.liferay.portal.model.ListType.organization.status=12017"
int statusId = 12017;
2) remove all users from the organization, before deleting the organization.

SSO (Single Sign-on) Using CAS

Single Sign-on (SSO) is a method to allow users to access multiple related but independent software systems while only needing to authenticate once. Many different single sign-on systems can be integrated with Liferay, and articles that describe this process are linked to below.

Setting up CAS server 

We will begin with setting up JA-SIG CAS server on Tomcat 5.x.x.
Download cas-server WAR from Liferay's download page or the whole distribution from here and drop the cas-web.war file into Tomcat's webapps dir. In a production environment The CAS server should really run on its own tomcat instance but for testing purposes we'll drop it in the same instance as our Liferay portal.
We'll need to edit the server.xml file in tomcat and uncomment the SSL section to open up port 8443.
<!-- Define a SSL HTTP/1.1 Connector on port 8443 -->
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />

Setting up the CAS client

Next we need to download the Yale CAS client from here. Get cas-client-2.0.11. Place the casclient.jar in ROOT/web-inf/lib of the Liferay install.

Generate the SSL cert with Java keytool

Now that we have everything we need, it's time to generate an SSL cert for our CAS server. Instructions and more information on SSL certs can be found here
But I found some typos and errors on that page. So following the instructions below should get you what you need.
In any directory (I use my root) enter the command:
keytool -genkey -alias tomcat -keypass changeit -keyalg RSA
Note: Be sure to use the keytool that comes with the Java VM (%JAVA_HOME%/jre/bin/keytool), as on some systems the default points to the GNU version of keytool, where the two seem incompatible.
Answer the questions: (note that your firstname and lastname MUST be hostname of your server and cannot be a IP address; this is very important as an IP address will fail client hostname verification even if it is correct)
Enter keystore password:  changeit
What is your first and last name?
[Unknown]:  localhost
What is the name of your organizational unit?
[Unknown]:
What is the name of your organization?
[Unknown]:
What is the name of your City or Locality?
[Unknown]:
What is the name of your State or Province?
[Unknown]:
What is the two-letter country code for this unit?
[Unknown]:
Is CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
[no]: yes
Then enter the command:
keytool -export -alias tomcat -keypass changeit -file %FILE_NAME% 
I use server.cert for %FILE_NAME%. This command exports the cert you generated from your personal keystore (In windows your personal keystore is in C:\Documents and Settings\<username>\.keystore)
Finally import the cert into Java's keystore with this command. Tomcat uses the keystore in your JRE (%JAVA_HOME%/jre/lib/security/cacerts)
keytool -import -alias tomcat -file %FILE_NAME% -keypass changeit -keystore %JAVA_HOME%/jre/lib/security/cacerts
Startup the CAS server
Now you are ready to startup your CAS server. Simply startup Tomcat and access CAS with https://localhost:8443/cas-web/login You should see the CAS login screen and no errors in your catalina logs.

Setting up Liferay Portal

web.xml 

Note: If you are using Liferay 4.2, this filter is already defined. All you have to do is modify the URL parameters, if your CAS server is at a different location. It's time to move on to configuring Liferay. In the webapps/ROOT/WEB-INF/web.xml file you will need to add a new filter and its mapping directly above the first existing auto login filter mapping. This new filter we just added will redirect all login attempts to the CAS server. If your hostname is different you can modify the init-params accordingly.

<filter> 
 <filter-name>CAS Filter</filter-name> 
 <filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class> 
 <init-param> 
  <param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name> 
  <param-value>https://localhost:8443/cas-web/login</param-value> 
 </init-param> 
 <init-param> 
  <param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name> 
  <param-value>https://localhost:8443/cas-web/proxyValidate</param-value> 
 </init-param> 
 <init-param> 
  <param-name>edu.yale.its.tp.cas.client.filter.serviceUrl</param-name> 
  <param-value>[http://localhost:8080/c/portal/login</param-value>] 
 </init-param> 
</filter>
If you use a ...serviceUrl param like above, after logging in with CAS, the browser will be redirected back to that serviceUrl. However, you can change it to the following and it will redirect back to the full URL that was originally requested. This allows you to have a deep link (e.g. to a certain layout with parameters for a portlet even) that is preserved through the CAS login process:
<init-param> 
       <param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name> 
       <!-- omit the colon and port number if it doesn't show in the browser URL (i.e. when running on port 80) -->
       <param-value>localhost:8080</param-value> 
    </init-param> 
 <filter-mapping> 
    <filter-name>CAS Filter</filter-name> 
    <url-pattern>/c/portal/login</url-pattern> 
 </filter-mapping>

Then add the following to the rest of the auto login filters
 <filter-mapping> 
    <filter-name>Auto Login Filter</filter-name> 
    <url-pattern>/c/portal/login</url-pattern> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
 </filter-mapping>

LIFERAY OVERVIEW

Portal and Web Application

The biggest difference between a portal and a web app is that a portal implies configurability.

however, most portals allow users to configure things to a certain extent.


The goal is to allow each users to see what they want and only what they want.


A portal is just a specific type of web application. “it provides a single point of entry to widely distributed information on the web



Collection of Web components are landing in one platform called Portal.

Each web components is called as Portlets.



What is Portal?

Portal is a web based application that commonly provides personalization, content aggregation , authentication..etc.

What is Portlet?

Portlets are pluggable user interface web components that are managed and displayed in a web portal. Portlets produce fragments of markup code that are aggregated into a portal page.


Java and Portal:

Java Community release Specifications for portlets. There are two Specification for Portal.

JSR168 ( Java Specification Request)

JSR286

These Specification described the behavior of Portlets inside Portal.


Internal Structure of Portal Page


How portal Page gets Generated?
















1. Each portletA, B, C, D,E, and F—generates the contents for the user. The contents might be static or generated dynamically, depending on the logic of the portlet application.

Each portlet is basically a Java application that runs some code when activated.

2. The container receives the contents generated by several portlets.

3. The container hands over the contents to the portal server.

4. The portal server creates the portal page, During page creation, the portal server applies the designated page layouts to place each portlet at the appropriate location.

5. The server sends the created page to the client device (the browser).

6. The browser displays the contents to the user.

Liferay Setup

1. Download Liferay Tomcat Bundled with Tomcat ( liferay-portal-tomcat-6.0.5.war ) from liferay site:

www.liferay.com--->Download→ click Bundled with Tomcat

2. Extract that bundle:

D:/LiferayPortal/server


3. Remove Sample data: sevencogs-Hook inside tomcat/web-apps

4. Database Configuration :

Create portal-ext.properties file inside:

(tomcat-6.0.\webapps\ROOT\WEB-INF\classes )

add this entries:

jdbc.default.driverClassName=com.mysql.jdbc.Driver jdbc.default.url=jdbc:mysql://localhost/lportal? useUnicode=true&characterEncoding=UTF-8& useFastDateParsing=false jdbc.default.username=root
jdbc.default.password=root

5. Go to bin Folder and Start Server :

D:\LiferayPortal\liferay-portal-5.2.3\tomcat-6.0.18\bin\startup.bat

- Gnaniyar Zubair

Wednesday, November 3, 2010

Lucene Search in Liferay

Lucene Search  In Liferay

What is Lucene?

Lucene powered by Akamai EdgeComputing is based on Jakarta Lucene, an open-source search application created by the Apache Software Foundation.

Jakarta Lucene is a high-performance, full-featured text search engine library written entirely in Java. The engine uses powerful, accurate, and efficient search algorithms. (http://jakarta.apache.org/lucene). Lucene includes the following functionality:

  • Provides the ability to search in many languages
  • Indexes any text-based file, such as HTML, or any file that can be converted to text
  • Supports ranked searching so the best results are returned first
  • Performs boolean and phrase queries
  • Enables fielded searching (e.g. searches can be submitted that focus on title, author, contents, etc)
  • Allows for date-range searching so users can access time-sensitive information .

How Lucene Works?

Creating an index file is a necessary step in implementing a search application with Lucene. An index is a special database that contains a compiled version of the Web site content. While the Lucene indexing API automates the creation of the index, the content that will be included in the index must be in text format. For every document type to be included in an index, the customer will need to utilize a parser or extractor. Lucene includes a sample HTML parser that receives a URL or the location of a file on a hard drive, parses the file, extracts the text from the HTML tags, and creates a Java string object that is passed to the Lucene indexing API.

To better understand how indexing works, The first step in the indexing process is to identify the content that should be indexed. Lucene creates a "Document object", which is a collection of name-value pairs that are called "fields". For example, one field might be Title, so the name-value pair would be "Title" - "Akamai Home Page". Each field is then assigned a "field object", which determines if the text associated with the field should be indexed, stored, and/or tokenized.

Lucene Search in Liferay

Example - Bookmark Portlet

1. Implement a com.liferay.portal.kernel.search.Indexer class, like this one: http://lportal.svn.sourceforge.net/viewvc/lportal/portal/trunk/portal-impl/src/com/liferay/portlet/bookmarks/util/Indexer.java?view=markup

This class is responsible for adding/updating/deleting documents to the index, it uses SearchEngineUtil which is an abstraction to the underlying search engine that is being used (currently you can use Solr or Lucene, Lucene is the default engine).

When adding a document you create a Document instance and pass it to SearchEngineUtil.addDocument along with the companyId. A com.liferay.portal.kernel.search.Document is just a collection of Fields, a com.liferay.portal.kernel.search.Field has a name and a value which is the content that you want to search for, for example, a Bookmark entry has a name "This is a Bruno bookmark entry.", later on, you can search for it with this query: name:"bruno".

A call to document.addText will add a Field to the document and its value will be filtered before indexed. All words that don't help with to bring relevant search results will be removed (like punctuation, pronouns, adverbs), in the example above the bookmark entry name would become "bruno bookmark entry". addText is usually called when the content to be indexed is a long text.

A call to document.addKeyword will add a Field to the document and its value will be indexed with no modification.

document.addUID is very important because it's used to create a unique identifier to the document in the index. You will need it to update or delete the document later. There are some other useful methods to Document, like addFile, that extracts contents from many file formats, and addModifiedDate which adds the current Date as a field to the document.

Some fields are commonly used: groupId, portletId, companyId, they are useful because you can narrow your searches to only show documents that were created in a certain community or company or even a specific portlet instance.

Indexer.getDocumentSummary is used by the Search portlet to aggregate all results from all portlets in just one place, DocumentSummary will be used to render each document in the search result listing.

2. Add a <indexer-class> to liferay-portlet.xml pointing to this class. Whenever you hit the button Re-index the Indexer re-index method will be called.

3. Whenever a Bookmark entry is added/updated/deleted from the database the Indexer is called to update the index accordingly. Search for Indexer at: http://lportal.svn.sourceforge.net/viewvc/lportal/portal/trunk/portal-impl/src/com/liferay/portlet/bookmarks/service/impl/BookmarksEntryLocalServiceImpl.java?view=markup

Observe the places where Indexer is called:

Indexer.addEntry(entry.getCompanyId(), folder.getGroupId(), folderId, entryId, name, url, comments, tagsEntries); Indexer.deleteEntry(entry.getCompanyId(), entry.getEntryId()); Indexer.updateEntry(entry.getCompanyId(), folder.getGroupId(), entry.getFolderId(), entry.getEntryId(), name, url, comments, tagsEntries);

If you encounter a NullPointerException while retrieving your portlet's indexer (portlet.getIndexerInstance() returning null), check the portletId returned by YourIndexer.getPortletId() and keep in mind the portletId outside the portal will be "<portlet-name in portlet.xml>_WAR_<webapp name>"

4. Now that Bookmark entries can be added/updated and removed from the index you are able to make searches requests to SearchEngineUtil, take a look at: http://lportal.svn.sourceforge.net/viewvc/lportal/portal/trunk/portal-impl/src/com/liferay/portlet/bookmarks/service/impl/BookmarksFolderLocalServiceImpl.java?view=markup

Look at the search method: public Hits search(long companyId, long groupId, long folderIds, String keywords, int start, int end)

It constructs a com.liferay.portal.kernel.search.Query instance and calls SearchEngineUtil.search(companyId, fullQuery, start, end) which returns a Hits instance.

A BooleanQuery is one implementation of Query, you can specify which field values MUST (AND operator), SHOULD (OR operator) or MUST_NOT (NOT AND operator) occurrences in the results. You can create composite BooleanQueries by adding one to another.

Start and end parameters are used to paginate the results, for example if start == 0 and end == 2, only the first two entries will appear in the result, if both are equal to QueryUtil.ALL_POS (-1) than all results will be returned.

5. Now that you have the search method you can use it in a jsp, for example: http://lportal.svn.sourceforge.net/viewvc/lportal/portal/trunk/portal-web/docroot/html/portlet/bookmarks/search.jsp?view=markup

This jsp calls the search method and iterates over com.liferay.portal.kernel.search.Hits which is a collection of Documents and represents the result of the search. The Hits class gives the score (the importance) of each document, tells you how long the search took and how many documents were found.

On each Document you can get the values of each field by calling document.get(String fieldName) or getValues in case the Field has multiples stored values.

6. If you want that your portlet will be listed in the Search portlet results you need to do one more step, create a com.liferay.portal.kernel.search.OpeanSearch implementation and add a <open-search-class> to your liferay-portlet.xml. Take a look at how this is implemented for Bookmark portlet:

http://lportal.svn.sourceforge.net/viewvc/lportal/portal/trunk/portal-impl/src/com/liferay/portlet/bookmarks/util/BookmarksOpenSearchImpl.java?view=markup

 



 Sibi Thomas

Tuesday, November 2, 2010

ALLOY POPUP


In Liferay's previous versions, we are using Liferay.Popup for popup window using jQuery.
As Liferay is moved to Alloy UI , Here is the code for Alloy Popup:


To Display some Html content in Alloy Popup:

<aui:script>
function callPopup(){
AUI().ready('aui-dialog', 'aui-overlay-manager', 'dd-constrain', function(A) {
var dialog = new A.Dialog({
title: 'DISPLAY CONTENT',
centered: true,
modal: true,
width: 500,
height: 400,
bodyContent: "This is testing content inside the popup"
}).render();
});
}
</aui:script>



Passing URL : Passing URL into Alloy Popup

<aui:script>
Liferay.provide(window,'<portlet:namespace />callPopup',
function(url1) {
var A = AUI();
var data = {};
var dialog = new A.Dialog(
{
centered: true,
destroyOnClose: true,
modal: true,
title: Liferay.Language.get('Display-Content'),
width: 600
}
).render();
dialog.plug(
A.Plugin.IO,
{
data: data,
uri: url1
}
);
},
['aui-dialog', 'aui-io']
);
</aui:script>

- Gnaniyar Zubair

Share & Enjoy

Twitter Delicious Facebook Digg Stumbleupon Favorites More