Wednesday 28 September 2016

onchange showing result


 <form name="fm"></form>
 <select onchange="companyChange()">
javascript

<script>
function companyChange(){
    alert("Can you Submit...?");
    document.fm.submit();
}
</script>

Jquery

<script>
$("#approvalStatus").change(function(){
alert("Can you Submit...?");
$("form[name='fm']").submit();
});
</script>

Monday 12 September 2016

Currency symbol for all countries



Code to get currency symbol:

    Currency currency = null;
    Locale locale = null;
    String currencySymbol = null;
  /*Get List of available countries from liferay country table*/
    List<Country> countryCode = CountryServiceUtil.getCountries();
   
    for(Country country:countryCode)
    {
        try{
            locale = new Locale.Builder().setRegion(country.getA2()).build();
            currency = Currency.getInstance(locale);   
               currencySymbol = currency.getSymbol(locale);
              System.out.println("currency symbol is......"+currencySymbol);}
        catch(Exception e){
            System.out.println("exception..."+e);
        }
    }

Passing form in ajax call


Submit HTML form with AUI Ajax

In case if you wish to pass html form with aui ajax, you need to change view.jsp code as per below snippet


<portlet:resourceURL var="testAjaxResourceUrl"></portlet:resourceURL>

<form id="testAjaxForm" action="">
    <input type="text" name="<portlet:namespace />param2">
    <input type="button" value="Submit" onclick="ajaxCall()">
</form>

<script type="text/javascript">
function ajaxCall(){
    AUI().use('aui-io-request', function(A){
        A.io.request('${testAjaxResourceUrl}', {
               method: 'post',

               data: {

                   <portlet:namespace />sampleParam: 'value2',
               },
               form:{
                   id:'testAjaxForm'
               },
               on: {
                       success: function() {
                        alert(this.get('responseData'));
                   }
              }
        });
    });
}
</script> 


package com.opensource.techblog.portlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.portlet.PortletException;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class TestAjaxPortlet extends MVCPortlet {

    private static Log _log = LogFactoryUtil.getLog(TestAjaxPortlet.class.getName());
   
    @Override
    public void serveResource(ResourceRequest resourceRequest,
            ResourceResponse resourceResponse) throws IOException,
            PortletException {
       
        String param = ParamUtil.get(resourceRequest, "param2", StringPool.BLANK);
       
        _log.info("Parameter is ==>" + param);
       
        resourceResponse.setContentType("text/html");
        PrintWriter out = resourceResponse.getWriter();
        out.print("You have entered ==>"+param);
        _log.info("Ajax call is performed");
        out.flush();
        super.serveResource(resourceRequest, resourceResponse);
    }
}
 















We can pass whole form in ajax call by serializing the form

In your script:

var str = $('#<portlet:namespace/>jobform').serialize();
$.ajax({
 type: "post",
 data: str,
 dataType: 'text',
 url: "<%=submitJobURL%>",
 async: false,
 success: function(data) {
  alert("success");
 }
});

And your form view in jsp:
<aui:form method="post" name="jobform">
<aui:input name="jobName" type="text" />
</aui:form>

Here jobform is your form id.

And we can get values in controller by normal way

String jobName = ParamUtil.getString(request,"jobName");

Thanks,
K.Mufas Mohammed Mydeen

Sharing liferay portlet to other website

Sharing liferay portlets is very easy.Liferay provides easy way to bring our portlet in other portals and websites. To share portlet Click on configuration of the portlet. For ex:Click on configuration of blogs portlet


Now you will be seeing a script given in the box.Check allow users to add blogs to any website and save.

Select the script and put in any website code.It will bring you the portlet view there.From there you can add a blog now.

Same thing can be done for any portlets and even for our custom portlets.

Initially if you put the script it will not be displayed.

In browser console you will be getting

Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

To resolve this you need to add
In portal-ext.properties

http.header.secure.x.frame.options=false 

and restart your server.It will work.By default it will be displayed.

Liferay Migration From 6.1 to 6.2

Steps for Migration

Step 1: Create dump of liferay6.1(eg : mysqlDump61.sql)

Step 2: Create New Database for Lifeay6.2 (eg: "mysqlDump62.sql")

Step 3: Setup a New Liferay Setup and start the server then finish the Configuration by pointing to the newly Created Database (eg :"mysqlDump62.sql") once setUp Finshed Stop the Server.(Note: Start With Fresh Liferay Bundels)

Step 4: Stop the Liferay6.2 Server.

Step 5: Import Lifeay6.1 dump(eg : mysqlDump61.sql) into Lifeay6.2 Database(eg:"mysqlDump62.sql")

Steps 7: Copy the "data" folder from Liferay6.1 server and replace the Liferay 6.2 "data" folder  with Liferay6.1 "data" folder in Liferay6.2 server.

Steps 8: Add following lines in "portal-setup-wizard.properties" file.

              dl.hook.impl=com.liferay.documentlibrary.util.AdvancedFileSystemHook
              dl.store.impl=com.liferay.portlet.documentlibrary.store.AdvancedFileSystemStore
              passwords.encryption.algorithm.legacy=SHA  // this property helps to remove conflicts in password encryption occurs in migrated database passwords.

Steps 9: Start the Liferay6.2 Server then you can able to notice that updating process taking place wait till update and migration complete.


How to Close Liferay PopUp in Liferay

Step :1

In "view.jsp"

           <liferay-portlet:renderURL var="dialogURL" windowState="                                                                             <%=LiferayWindowState.POP_UP.toString() %>">

    <liferay-portlet:param name="jspPage" value="/html/dialog.jsp" />
    </liferay-portlet:renderURL>

    <aui:button  name="openDialog" type="button" value="open-dialog" />

// If you  Click on "openDialog"  button popup will be triggered and opened, in that "content.jsp" content's will be loaded.If you Click on "closeDialog" button  popUp  will be closed



    <aui:script use="liferay-util-window">

    A.one('#<portlet:namespace/>openDialog').on('click', function(event) {
    Liferay.Util.openWindow({
    dialog: {
    centered: true,
    height: 300,
    modal: true,
    width: 400
    },
    id: '<portlet:namespace/>dialog',
    title: '<liferay-ui:message key="i-am-the-dialog" />',
    uri: '<%=dialogURL %>'
    });
    });
  
// this below code will helps to Close the popup, once the action triggered from the child page "content.jsp"

Liferay.provide(
     window,
     'closePopup',
     function(dialogId) {
     var dialog = Liferay.Util.getWindow(dialogId);

     Liferay.fire(
     'closeWindow',
     {
    
     id:'<portlet:namespace/>dialog'
     }
     );
     },
     ['aui-base','liferay-util-window']
     );

    </aui:script>


Step 2:

In "content.jsp"



<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
  
  
    <aui:button name="closeDialog"  type="button" value="close" />
    
    <aui:script use="aui-base">
    A.one('#<portlet:namespace/>closeDialog').on('click', function(event) {
    
    // Let's suppose that "data" contains the processing results

    // Invoke a function with processgin results and dialog id
     Liferay.Util.getOpener().closePopup('<portlet:namespace/>dialog');// this will will call the closePopup fuction in parent page where the popUp is initiated "view.jsp".

    });
    </aui:script>
  

Liferay - Custom Password Validation (Strength)

Custom password validation strength based on password poloices


  • Lowercase character        eg:RegExp   (?=.*[a-z])
  • Uppercase character        eg:RegExp   (?=.*[A-Z])
  • Digit                                   eg:RegExp   (?=.*[0-9])
  • Symbol                              eg:RegExp   (?=.*[@#$^&*!~])
 I am using Regular Expression   

<aui:input id="newPassword" name="newPassword" type="password"
                                placeholder="New Password" label="">

        <aui:validator  name="custom"  errorMessage="Password should contain atleast one
 (Uppercase Letter,lowercase Letter,Numeric digit and Symbol)" >
                                                                        
          function(val, fieldNode, ruleValue) {
              var passwordPattern = new RegExp("(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[@#$^&*!~])");
                           var result = passwordPattern.test(val);
                                    if(result){
                                             return result;
                                        }else{
                                               return result;
                                            }
                                    }
           </aui:validator>     
 </aui:input>

Tuesday 6 September 2016

Liferay 6.2 Portal-Properties

Liferay Service Builder Concept

Theme display signed in or Not signed in

<%if(themeDisplay.isSignedIn()){ %>
       <aui:a href="<%=demoscheduleAdd.toString() %>"><button class="demoform">Schedule Demo</button></aui:a>
       <%}else { %>
       <a href="/course_catalog?p_p_id=58&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&saveLastPath=false&_58_struts_action=%2Flogin%2Flogin"> <button class="demoform">Schedule Demo</button></a>
       <%} %>  

portal-ext.properties code

portal-ext.properties

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

How to create action & render url

How to create renderURL

<%
 PortletURL renderUrlFromJSP = renderResponse.createRenderURL();
 renderUrlFromJSP.setParameter("param1", "This portletULR is created with API in JSP");
 renderUrlFromJSP.setWindowState(LiferayWindowState.NORMAL);
 renderUrlFromJSP.setPortletMode(LiferayPortletMode.VIEW);

%>
<a href="<%=renderUrlFromJSP%>">Render Url created by JAVA API in JSP</a>



How to create ActionURL from renderResponse object

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="javax.portlet.PortletURL"%>
<portlet:defineObjects />
<%
    PortletURL actionURL = renderResponse.createActionURL();
    actionURL.setParameter("javax.portlet.action", "someProcessAction");
%>

<a href="<%=actionURL%>">Call Process Action</a>

@ProcessAction(name="someProcessAction")
public void someProcessAction(ActionRequest actionRequest, ActionResponse actionResponse){
String value = ParamUtil.getString(actionRequest, "some-parameter");
    System.out.println("#######Calling some process action##############");
}



This is the easiest way to create action URL. For example
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<portlet:actionURL var="actionURL" name="someProcessAction"/>
 <a href="<%=actionURL%>">Call Process Action</a>