Saturday, 26 May 2012

Index Sorting

Sorting Mechanism for Index

like "1" ,"1.1" , "1.2.1" and more


Sorting logic using Comparator


/**
     * this is only for integer type index
     * {"1", "1.1", "1.1.1", "1.10", "1.10.1", "1.10.2", "1.11", "1.2"}
     * kind of sorting
     */



private static Comparator<String> comparatorIndices = new Comparator<String>() {

            
        public int compare(String o1, String o2) {
            String[] c1 = o1.contains(".")?o1.split("\\."):new String[]{o1};
            String[] c2 = o2.contains(".")?o2.split("\\."):new String[]{o2};
          
            int c1l = c1.length;
            int c2l = c2.length;
          
            int length;
          
            if(c1l == c2l){
                length = c1l;
                for(int i=0;i<length;i++){
                    if(!c1[i].equalsIgnoreCase(c2[i])){
                        return Integer.valueOf(c1[i]).compareTo(Integer.valueOf(c2[i]));
                    }
                }
                return 0;
            }
          
            if(c1l < c2l){
                length = c1l;
                for(int i=0;i<length;i++){
                    if(!c1[i].equalsIgnoreCase(c2[i])){
                        return Integer.valueOf(c1[i]).compareTo(Integer.valueOf(c2[i]));
                    }
                }
                return -1;
            }
          
            if(c1l > c2l){
                length = c2l;
                for(int i=0;i<length;i++){
                    if(!c1[i].equalsIgnoreCase(c2[i])){
                        return Integer.valueOf(c1[i]).compareTo(Integer.valueOf(c2[i]));
                    }
                }
                return -1;
              
            }
            return 0;
        }
    };
   

You can also generate Tree using DefaultMutableTreeNod



public static void CreaateTree{

String[] str = new String[]{"1", "1.1", "1.1.1", "1.10", "1.10.1", "1.10.2", "1.11", "1.2", "1.2.1", "1.3", "1.3.1", "1.4", "1.4.1", "1.5", "1.5.1", "1.6", "1.6.1", "1.7", "1.7.1", "1.8", "1.8.1", "1.9", "1.9.1", "1.9.2", "2", "2.1", "2.1.1", "2.10", "2.10.1", "2.10.2", "2.11", "2.12", "2.13", "2.2", "2.2.1", "2.2.1.1", "2.2.1.1.1", "2.2.1.1.1.1", "2.2.1.2", "2.3", "2.3.1", "2.4", "2.4.1", "2.5", "2.5.1", "2.6", "2.6.1", "2.7", "2.7.1", "2.8", "2.8.1", "2.9", "2.9.1", "2.9.2", "3", "3.1", "3.1.1"};
        

Collections.sort(Arrays.asList(str), comparatorIndices);
       
        DefaultTreeModel model;
        DefaultMutableTreeNode top = new DefaultMutableTreeNode("0",true);
        model = new DefaultTreeModel(top);
       
        for(String string:str){
            DefaultMutableTreeNode findTreeNode = findTreeNode(getParentId(string));
            if(null != findTreeNode){
                top = findTreeNode;
                top.add(new DefaultMutableTreeNode(string,true));
            }else{
                top.add(new DefaultMutableTreeNode(string,true));
            }
        }
}



public static String getParentId(String child){
        if(null != child && !"".equalsIgnoreCase(child)){
            if(-1 != child.lastIndexOf(".")){
                return child.substring(0, child.lastIndexOf("."));
            }else{
                return "0";
            }
        }
        return "";
    }
   
    public static DefaultMutableTreeNode findTreeNode(String nodeId) {
        DefaultMutableTreeNode rootNode =
                (DefaultMutableTreeNode) model.getRoot();
        DefaultMutableTreeNode node;
        String tmp;
        Enumeration nodes = rootNode.depthFirstEnumeration();
        while (nodes.hasMoreElements()) {
            node = (DefaultMutableTreeNode) nodes.nextElement();
            tmp = (String) node.getUserObject();
            if (nodeId.equals(String.valueOf(tmp))) {
                return node;
            }
        }
        return null;
    }





Sunday, 22 January 2012

Liferay Client Side IPC using javaScript and call Icefaces Backing bean

To Communicate portlets by clientSide using javaScript,
Liferay Provide javascript function trigger and bind.
you can trigger a event from one portlet and send data to another 
portlet where you bind event using liferay javaScript function.


  • Trigger a event from sender Portlet.
 

   Liferay.trigger('event-name', {parameter: 'parameter'});



  • Now in another receiver portlet you have to bind the same event-name which one you have trigger from sender portlet.

      Liferay.bind('event-name',
             function(event, data){
                
                   var message = data.
parameter;
        }); 



  •   In Icefaces portlet if you want to communicate with you backing bean.Icefaes support iceSubmit(form,element,event).So you can trigger iceface commandButton or CommandLink using javaScript.Icefaces commandButton/Link have actionListener/Action fired on iceSubmit javaScript Call.

             Liferay.bind('event-name',
                  function(event, data){
                    var message = data.
parameter;
                    var form = document.getElementById('formName');
                    var element = document.getElementById('element');//button/Link
                    var evObj=document.createEvent("MouseEvents");
evObj.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);

                    iceSubmit(form,element,evObj);
                  // or you can trigger element click 
                 // element.click();
             });




............................................................................ 

Monday, 2 January 2012

Icefaces Facelet Custom Component

How to create Icefaces Facelet Custom Component.

Do the following configuration
Add following Jar files
    el-ri.jar
    icefaces-facelets.jar
    servlet-api.jar
   
in web.xml

<context-param>
    <param-name>facelets.DEVELOPMENT</param-name>
    <param-value>true</param-value>
</context-param>

<context-param>
    <param-name>facelets.LIBRARIES</param-name>
    <param-value>/WEB-INF/facelets/tags/externalcomp.taglib.xml</param-value>
</context-param>


in faces-config.xml

<application>
    <view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler</view-handler>
</application>


now create "externalcomp.taglib.xml" in /WEB-INF/facelets/tags/ and add following

<facelet-taglib>
    <namespace>http://www.abctaglib.com/jsf</namespace>
    <tag>
        <tag-name>MyComponent</tag-name>
        <source>mycomponent.jspx</source>
    </tag>
</facelet-taglib>

   
Now you can use your custom tag in your jspx file including folloeing content..


<ui:composition xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ice="http://www.icesoft.com/icefaces/component"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:mycomp="http://www.abctaglib.com/jsf">
               
        <mycomp:MyComponent .... here you can pass your parameter ....  ></mycomp:MyComponent>
        /// like
        <mycomp:MyComponent myvalue="10"></mycomp:MyComponent>
        //.....
        //.....
       
</ui:composition>



<mycomp:MyComponent myvalue="10"></mycomp:MyComponent>

You can use myvalue parameter in "mycomponent.jspx".
for example in "mycomponent.jspx" you want to print "myvalue",

<ice:outputText id="fromMyValue" value="#{myvalue}" />




...................................................................................................................

Friday, 30 December 2011

IPC - Inter Portlet Communication using "Public Render Parameter feature"

To Communicate two Portlet using Public Render Parameter...

JSR286 Support the functionality of Public-Render-Parameter.Using this you can share value in Portlets.

Some few Configuration for IPC.

If you have two Portlet and you want to share parameter named "paramName" which share value in both Portlet.

1). You have to add following tag in both Portlet.xml

<portlet-app ....>
     <portlet> .. </portlet>
     <public-render-parameter>
        <identifier>paramName</identifier>
        <qname xmlns:x="http://xyz.com/param">x:
paramName</qname>
     </public-render-parameter>  
</portlet-app>

here <identifier>paramName</identifier> "paramName" is your identifire ,which you use to set and get Value.

A QName is a qualified name. Using a QName allows events to be name-spaced properly so that no two event names are identical 


2). Also you have to add supported-public-render-parameter in both portlet.xml


<portlet-app ....>
     <portlet>
     <supported-public-render-parameter>paramName</supported-public-render- parameter>
     </portlet>
     <public-render-parameter>
        <identifier>paramName</identifier>
        <qname xmlns:x="http://xyz.com/param">x:
paramName</qname>
     </public-render-parameter>  
</portlet-app>
3). Now we have to set Render Parameter. Do following in Sender Portlet

 In ProcessAction(..) method 


   public void processAction(ActionRequest req, ActionResponse res)
         throws IOException, PortletException {
        // Your Code ...
                 res.
setRenderParameter("parameName", "value");
        }


4). Now last Configuration in another Portlet get value from Parameter using PortletRequest......


    ParamUtil.getString(portletRequest,"parameName");



5). to remove render Parameter 

public void processAction(ActionRequest req, ActionResponse res)
         throws IOException, PortletException {
        // Your Code ...
                 res.
removePublicRenderParameter("parameName");
        }



6). If you are use IPC in JSF,Icefaces Portlet one thing to remember...
add following tag in Portlet.xml

<portlet>
......
   <init-param>
       <name>com.sun.faces.portlet.SAVE_REQUEST_SCOPE</name>
       <value>true</value>
    </init-param>
<portlet>






....................................................................................

Sunday, 18 December 2011

Build EXT Service with "id" column - [JDBCExceptionReporter:101] Unknown column 'xxxxxxx_.id_' in 'field list'

In Liferay5.2.3 when you are trying to build a sevice with Column name "id" not
a Id,ID or etc other than "id".

for Example a table- ExampleTable has field


id long not null,
name varchar(30),
emailAddress varchar(30),

After Creating Table when you creat a Ext Service and trying to call LocalSrviceUtil ,Liferay-Hibernate  gives error like,

 [JDBCExceptionReporter:101] Unknown column 'ExampleTable0_.id_' in 'field list'


..Liferay portal doesnot support for "id" name column.

To remove these type of error,


Just rename the table field "id" to "id_" you doesn't have to rebuild Service.







 

Thursday, 15 December 2011

Run Your Liferay on Shared Server.

1.Download Liferay Portal
            http://www.liferay.com/downloads/liferay-portal/available-releases

2.Extract Portal on your Shared Server.

3.Goto ..\liferay-portal-Version\tomcat-6.0.18\webapps\ROOT\WEB-INF\classes\

4.Edit portal-ext.properties  , if file is not there create a new file same name.

5. put cofiguration of database.(or it will take default liferay DB HSQL )


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

       #
       #  if running from sub folder.because you are running on shared.
       #  change Root foleder naem to your context.
       #
      
      portal.ctx=/portal    


       #
       #  Document ,Articles and images Stored

       # 
     
        liferay.home=/home/lportal/liferay
create a .htaccess file to Liferay root directory 
and Add following contentc to file ..
     SetHandler jakarta-servlet
     SetEnv JK_WORKER_NAME ajp13

Sunday, 11 December 2011

Liferay Delete User From OpenSSO

  • Deploy opensso-client-jdk15/opensso-client-jdk14 as per your JDK Version in Tomcat.
  •  
  • Click on Configuration
  • Client SDK is successfully configured.
    AMConfig.properties created at
    C:\WINDOWS\system32\config\systemprofile\OpenSSOClient\_Program Files_Apache Software Foundation_Tomcat 7.0_webapps_opensso-client-jdk15_AMConfig.properties
  • Now Create a Java/Web Project ..Or Create a Portlet (Liferay).
  • Copy AMConfig.properties to your Application.(In Source Folder,not in a Package)
  • Add Lib : openssoclientsdk.jar in Lib folder.
  • Write Java File ......with Below Two Methods..
  •  
  •      

Infinidb _CpNoTf_ problem

infinidb table with a varchar column insert string as a '_CpNoTf_' while using Cpimport. The Problem is occured if inserted string ...