Tuesday, October 29, 2013

solr configuration problem with Liferay 6.0

Dear friends,

In this post I am writing the solution for solr exception, usually it happens when you configure solr with Liferay portal. Especially if you are using same tomcat(Liferay's tomcat) bundle for solr.

I think you may facing the problem like, not able to delete pages after configuring solr engine with you portal.You may get exceptions like as fallows.

14:40:42,293 ERROR [SolrIndexSearcherImpl:75] org.apache.solr.client.solrj.SolrServerException: Error executing query
org.apache.solr.client.solrj.SolrServerException: Error executing query
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:95)

4:40:42,294 ERROR [SearchReaderMessageListener:34] Unable to process message {destinationName=liferay/search_reader, responseDestinationName=liferay/search_reader/response, responseId=93563af8-e4ba-4e88-9bbe-5028898b79ef, payload={companyId=10132, document=null, documents=null, end=-1, id=null, ids=null, query=+portletId:19 +threadId:20706, searchEngineCommand=SEARCH, sorts=[{fieldName=null, type=0, reverse=false}, {fieldName=modified, type=6, reverse=true}], start=-1}, values=null}
com.liferay.portal.kernel.search.SearchException: Error executing query
at com.liferay.portal.search.solr.SolrIndexSearcherImpl.search(SolrIndexSearcherImpl.java:77)
at com.liferay.portal.kernel.search.messaging.SearchReaderMessageListener.doCommandSearch(SearchReaderMessageListener.java:41)
at com.liferay.portal.kernel.search.messaging.SearchReaderMessageListener.doReceive(SearchReaderMess

For this root cause is, solr is recommended to configure in separate tomcat. Still its not a problem if you have configured with liferay server. But you need to add two important things as mentioned below.

1. Add the fallowing line in schema.xml of solr and index you are trying to access
          <field name="modified" type="text" indexed="true" stored="true" />  
2. Change the SolrIndexSearchImpl.java class add fallowing code with class method "subset" replacing the original code  i,e
         
                 for (String name : names) {
                                    Field field = new Field(
                                    name, solrDocument.getFieldValue(name).toString(), false);
                                   document.add(field);
                                                      }


 replace above code with fallowing code

           for (String name : names) {  
                           Field field = new Field(name,  
                          ArrayUtil.toStringArray(solrDocument.getFieldValues(name).toArray()), false); 
                          document.add(field);  
                                                  } 
I hope it may help somebody. 

Thanks Guys,

Monday, August 5, 2013

IFRAME problem with IE

Hi guys,

I experienced there is a problem with 'Iframe' tag especially with IE(Internet Explorer). The problem is, IE not allow third party cookies. Hence you may get problem with functionality with Iframe.

Ex: If you are working for www.yoursite.com  and want to use feature of other site using iframe, you may write code like as below,
<iframe src="www.anothersite.com" /> 

The problem is when your site loaded, cookie will be stored in the browser.In the same page or site you are trying to call another site's content, so that page cookie will be third party cookie for browser. Some times its not allowed in IE.
This you can check with the 'Evil eye' icon in the bottom of your browser.

So there i simple way where you can set cookies and make your page safer('Safer' because even if you are not using privacy statement for your site, you can get rid of cookie problem).

Solution:

Use p3p, in all you site by including below line in starting of your page which all are in Iframe.

response.setHeader("P3P","CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'")

 That's all .......!

Thanks to Viral Patel.

If you are using PHP or other language you can go through this post: Iframe problem with IE

For more information for CP parameters you can go through this post: P3P possible parameters


Regards
Praveen Pujar

Wednesday, June 26, 2013

Detection of first time visitor to the website using jquery.

Hi guys,


Today I was working with one requirement, in which I would find the first time visitor to my portal/website(I am using Liferay portal for website) for some business needs. Lets say to Wish like welcome note with beautiful picture or like asking user to agree terms and condition before going opening website, etc, etc.... I think most of the time we need this feature. Hence I am writing this posts, may be useful for somebody.


HOW TO DETECT FIRST TIME VISITOR TO THE WEBSITE???????

If we are using any web technologies or I would say smart frameworks like LIFERAY, we can make use of Jquery code to detect. So how???? Lets see how we can do in Liferay using themes, using Jquery in it. 

  • If you are using your custom theme, you can add the jquery code in main.js file. Which you can find in <theme-name>/docroot/_diffs/js/main.js
  • lets write jquery code, we can make use of cookies.
            lets give the cookie name to your site as  "myCookie", lets set the cookie name.
           
 if(!($.cookie('myCookie')))
  {
      alert("Welcome, Thanks for visiting");
      $.cookie('myCookie','visited', { path: '/', expires: 10000 });
  }
else
 {
     alert("Already visited.");
 }
That's all guys. Use the above code in main.js of your theme and you can detect the first time visitor.
IMPORTANT NOTES 
  1. To work with cookies of Jquery you should have the jquery.cookie.js plugin. You can find that in   jquery.cookie.js
  2. If you want to know more about attributes I have used for cookies you can go through Cookies Properties



Friday, October 19, 2012

Adding custom field in registration page is Liferay

Hi, guys Liferay is such a beautiful portal technology, it has one pretty nice feature about custom fields.

This post is how to use that custom field feature in registration field in liferay

Here are the steps to be followed
1. Click on control panel > User > Custom attributes > Add Custom attributes.

2. Here we need to give a key (name) and type of the field.  

3. For eg. We will have an Field called Designation added which is a text field. 
    Key :   Designation
    Type : Text-field(Indexed) and save. 

4. Then add the custom attribute taglib in the create_account.jsp in /tomcat/webapps/ROOT/html/portlet/login as follows:

<liferay-ui:custom-attribute-list

            className="com.liferay.portal.model.User"

            classPK="<%= 0l %>"

            editable="<%= true %>"

            label="<%= true %>"

      /> 
    But this field will not appear on the create account page because permissions are not given.


   Hence to permission click on action tab of that custom attribute(here eg.Designation) and permissions

 Note: very important thing is assigning permission for added custom field to guest

    1. Here for guest we give permission for view and update.
  
    2. Now in the create account page this field will appear.


And you can get those value in expando table in liferay, you can fetch the value using expandoBridge class.