Friday, 6 February 2015

How to embed a Web Content on your theme?

Requirement:
If you want to display any web content in all the pages then embed that web content in to  theme.



Open portal_normal.vm file of your theme(docroot/_diff/templete/portal_normal.vm)

<pre>
<div id="image-slider">





#set ($VOID = $velocityPortletPreferences.setValue('groupId', $themeDisplay.getCompanyGroupId().toString()))
#set ($VOID = $velocityPortletPreferences.setValue('articleId', $webContentID))
#set ($VOID = $velocityPortletPreferences.setValue('portletSetupShowBorders', 'false'))
#set ($portlet_id = '56')
#set ($my_portlet_id = "${portlet_id}_INSTANCE_ABC1")
$theme.runtime($my_portlet_id, "", $velocityPortletPreferences.toString())
$velocityPortletPreferences.reset()
</div>
</pre>


                             likewise 


<pre>
<div id="image-slider">





#set ($VOID = $velocityPortletPreferences.setValue('groupId', $themeDisplay.getScopeGroupId().toString()))
#set ($VOID = $velocityPortletPreferences.setValue('articleId', '16806'))
#set ($VOID = $velocityPortletPreferences.setValue('portletSetupShowBorders', 'false'))
#set ($portlet_id = '56')
#set ($my_portlet_id = "${portlet_id}_INSTANCE_1234")
$theme.runtime($my_portlet_id, "", $velocityPortletPreferences.toString())
$velocityPortletPreferences.reset()
</div>
</pre>

If you want to put two different instance of web content display portlet
 on same page and want to display different web content on it, You'll 
need to modify its instance id.
So make sure value for instance id in header and footer is different.

#set ($my_portlet_id = "${portlet_id}_INSTANCE_1234")


If you have used _INSTANCE_1234 in header then use _INSTANCE_5678 in footer code.

Sunday, 11 January 2015

Search Container for Boolean value


Here we are storing paymentStatus as boolean(0,1), like 1=true=paid and 0=false=Unpaid when we display data using search Container by using property="paymentStatus"it will display true or false.But we want to dispaly Paid for true and Unpaid for False




<% 
String status;
if(info.getPaymentStatus()){
status="Paid";
}else{
status="Not Paid";
}
%>
<liferay-ui:search-container-column-text name="Payment Status" value="<%=status %>" />

<%
if(select.equalsIgnoreCase("RequestedForCancel")){
%>
<liferay-ui:search-container-column-jsp path="/html/Admin/bookingdetail/actionBookingDetails.jsp" name="Action">
</liferay-ui:search-container-column-jsp>

<%}%>

Wednesday, 7 January 2015

While select value from drop down popup will display

While select value from drop down popup will  display ,that popup is another jsp page you can display data on that popup .


view.jsp

<aui:script>
var myPop;
       function abc(url,abc){
       
              AUI().use('aui-dialog', 'aui-io', function(A)
              {
                 
                  myPop = new A.Dialog({

                  title: 'Nags Admin Reservation',

                  centered: true,

                  modal: true,

                  width: 800,

                  height: 250,

                  }).plug(A.Plugin.IO, {uri: url}).render();

              });

       }

</aui:script>
 

<%

PortletURL popURL = renderResponse.createRenderURL();
popURL.setParameter("jspPage", "/html/Admin/adminreservation/adminPopUp.jsp");
popURL.setWindowState(LiferayWindowState.POP_UP);
List<CarDetails> card= CarDetailsLocalServiceUtil.searchByType(type);

%>
<td>
<b>Model* </b><br><select id="model" name="model"  onchange="javascript:renderCar()" >
<option value="">---select---</option>
  <% for(CarDetails car : card){%>
<option value="<%=car.getModel() %>" <%if(car.getModel().equalsIgnoreCase(model)){ %>selected="selected" <%} %> ><%=car.getModel()%></option>
<%} %>
</select>

</td>



function renderCar() {
var url = "<%=popURL%>";
url = url+"&model="+$("#model").val() + "&type=" + "<%=type%> ";
abc(url);
}

 adminPopUp.jsp

<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@page import="javax.portlet.PortletURL"%>
<%@page import="com.liferay.portal.kernel.util.ListUtil"%>
<%@page import="com.slayer.model.CarDetails"%>
<%@page import="java.util.List"%>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@page import="com.liferay.portal.kernel.dao.search.ResultRow"%>
<%@page import="com.liferay.portal.kernel.dao.search.SearchContainer"%>
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@page import="com.slayer.service.CarDetailsLocalServiceUtil"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects/>


<%
        String model = ParamUtil.getString(renderRequest, "model");
        String type = ParamUtil.getString(renderRequest, "type");

        List<CarDetails> carDetails = CarDetailsLocalServiceUtil.searchByModel(model,type);
   
%>

<liferay-ui:search-container  delta="5" emptyResultsMessage="Sorry. There are no items to display." >
        <liferay-ui:search-container-results total="<%=carDetails.size()%>"
            results="<%=ListUtil.subList(carDetails, searchContainer.getStart(),searchContainer.getEnd())%>" />
        <liferay-ui:search-container-row modelVar="car" className="CarDetails">
       
        <liferay-ui:search-container-column-text name="Type" property="type"/>
        <liferay-ui:search-container-column-text name="Color" property="color"/>
        <liferay-ui:search-container-column-text name="Year" property="year"/>
        <liferay-ui:search-container-column-text name="Licence" property="licence"/>
        <liferay-ui:search-container-column-text name="model" property="model"/>
        <liferay-ui:search-container-column-text name = "Select" >
        <input type = "radio" id="<%=car.getLicence() %>" name ='select'
        cartype= "<%=car.getType() %>"
        licence= "<%=car.getLicence() %>"
        Year= "<%=car.getYear() %>"
        Color= "<%=car.getColor() %>"
        value = "<%=car.getLicence() %>" onclick="javascript:choose(this);"/>
        </liferay-ui:search-container-column-text>
       
        </liferay-ui:search-container-row>
    <liferay-ui:search-iterator searchContainer="<%=searchContainer%>" />
    </liferay-ui:search-container> 
   
   
    <script>

function choose(va) {
   
    var typeOriginal = parent.window.document.getElementById("typeOriginal");
    var yearOriginal = parent.window.document.getElementById("yearOriginal");
    var colorOriginal = parent.window.document.getElementById("colorOriginal");
    var licenceOriginal = parent.window.document.getElementById("licenceOriginal");
   
    licenceOriginal.value = $(va).attr('licence');
    typeOriginal.value = $(va).attr('cartype');
    yearOriginal.value = $(va).attr('Year');
    colorOriginal.value = $(va).attr('Color');
   
     window.parent.myPop.close();
}



</script>
   

 


Monday, 29 December 2014

Date Picker using java script

<form action="<%=iteratorURL %>" method="post">
<input type="text" name="fromdate" id="fromdate" readonly="readonly" placeholder="From Date"/>
<input type="text" name="todate"  id="todate" readonly="readonly" placeholder="To Date"/>
</form>

<script type="text/javascript">
 $(document).ready(function(){
       $(function() {
       
           $('#fromdate').datepicker({
               minDate: 0,
               dateFormat: 'mm/dd/yy',
                onClose: function (selectedDate) {
                   $("#todate").datepicker("option", "minDate", selectedDate);
               }
           });
           $('#todate').datepicker({
               minDate: 0,
               dateFormat: 'mm/dd/yy'
              
               /* onClose: function (selectedDate) {
                   $("#ExpectedDateStart").datepicker("option", "", selectedDate);
               } */
           });
              
       });
 });
</script>

 IF YOU WANT TO DISPLAY PREVIOUS  DATE ALSO IN FIRST DATE PICKER BOX THEN USE THIS

<script type="text/javascript">
 $(document).ready(function(){
       $(function() {
       
           $('#fromdate').datepicker({
               //minDate: 0,
               dateFormat: 'mm/dd/yy' ,
                onClose: function (selectedDate) {
                   $("#todate").datepicker("option", "minDate", selectedDate);
               }
           });
           $('#todate').datepicker({
               //minDate: 0,
               dateFormat: 'mm/dd/yy'
              
               /* onClose: function (selectedDate) {
                   $("#ExpectedDateStart").datepicker("option", "", selectedDate);
               } */
           });
              
       });
 });
</script> 

Tuesday, 23 December 2014

HOW TO SAVE PASSWORD IN TEXT FORMAT IN LIFERAY USER TABLE

portal-ext.properties file


passwords.encryption.algorithm=NONE 


save  and restart the server
then create a account and check user table password will store in text .

Sunday, 21 December 2014

Finder Tags in liferay

 Search field with the below drop-down texts:
1. All Bookings
2. Executed Bookings
3. Cancelled Bookings
4. Cancelation Requests.

service.xml
 <entity name="BookingInfo" local-service="true" remote-service="false">
        <column name="bookingId" type="String" primary="true"/>
        <column name="customerId" type="String" />
        <column name="carId" type="String" />
        <column name="carType" type="String" />
        <column name="emailId" type="String" />
        <column name="phNumb" type="String" />
        <column name="fromlocation" type="String" />
        <column name="toLocation" type="String"/>
        <column name="dateOut" type="String" />
        <column name="timeOut" type="String" />
        <column name="dateIn" type="String" />
        <column name="timeIn" type="String" />
        <column name="dateDueIn" type="String" />
        <column name="timeDueIn" type="String" />
        <column name="insurance" type="String" />
        <column name="paymentStatus" type="boolean" />
        <column name="amount" type="String" />
        <column name="carStatus" type="String" />
      
        <column name="cardType" type="String" />
        <column name="cardNumb" type="String" />
        <column name="cardExpMon" type="String" />
        <column name="cardExpYear" type="String" />      
      
        <order>
            <order-column name="bookingId" order-by="desc" />
        </order>
      
        <finder return-type="Collection" name="phNumb">
            <finder-column name="phNumb" />          
        </finder>
      
        <finder return-type="Collection" name="email">
            <finder-column name="emailId" />
            <finder-column name="paymentStatus" />                  
        </finder>
      
  
              
        <finder return-type="Collection" name="carStatus">
            <finder-column name="carStatus" />          
        </finder>

  BookingInfoLocalServiceImpl.java

 public class BookingInfoLocalServiceImpl extends BookingInfoLocalServiceBaseImpl {
     
    public List<BookingInfo> searchByPhNumb(String phNumb) throws SystemException {
      
        List<BookingInfo> booking = bookingInfoPersistence.findByphNumb(phNumb);
      
        return booking;
    }
  
    public List<BookingInfo> searchEmail(String email) throws SystemException {
      
        List<BookingInfo> booking = bookingInfoPersistence.findByemail(email, true);
      
        return booking;
    }
  
    public List<BookingInfo> searchByCarStatus(String carStatus) throws SystemException {
      
        List<BookingInfo> booking = bookingInfoPersistence.findBycarStatus(carStatus);
      
        return booking;
    }
}


view.jsp

<%@page import="javax.portlet.ActionRequest"%>
<%@page import="javax.portlet.ActionResponse"%>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portal.kernel.dao.search.SearchContainer"%>
<%@page import="com.liferay.portal.kernel.util.ListUtil"%>
<%@page import="com.slayer.service.BookingInfoLocalServiceUtil"%>
<%@page import="com.slayer.model.BookingInfo"%>
<%@page import="java.util.List"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="javax.portlet.PortletURL"%>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<portlet:defineObjects />

<style>

.href{
text-decoration: none;
}
</style>

 <%
List <BookingInfo> bookingInfo = BookingInfoLocalServiceUtil.getBookingInfos(0, -1);

PortletURL iteratorURL = renderResponse.createRenderURL();
iteratorURL.setParameter("jspPage", "/html/Admin/bookingdetail/view.jsp");

String select = "all" ;
String abc = "all";

select = renderRequest.getParameter("select");
 abc =(String) request.getAttribute("select");
if(select==null){
    select="all";
   
    bookingInfo = BookingInfoLocalServiceUtil.getBookingInfos(0, -1);
}if(abc==null){
    abc = "all";
}if(select.equalsIgnoreCase("cancelReq") || abc.equalsIgnoreCase("cancelReq")){
    select ="cancelReq";
    bookingInfo = BookingInfoLocalServiceUtil.searchByCarStatus("cancelReq");
}
if(select.equalsIgnoreCase("Cancelled") || abc.equalsIgnoreCase("Cancelled")){
    select ="Cancelled";
    bookingInfo = BookingInfoLocalServiceUtil.searchByCarStatus("Cancelled");
}

if(select.equalsIgnoreCase("Executed")||abc.equalsIgnoreCase("Executed")){
    select="Executed";
    bookingInfo=BookingInfoLocalServiceUtil.searchByCarStatus("Executed");
}
%>

<div>
<form action="<%=iteratorURL %>" method="post">
<select name="select">
<option value="all" <%if(select.equalsIgnoreCase("all")){ %> selected="selected" <%} %>>All Bookings</option>
<option value="Executed" <%if(select.equalsIgnoreCase("Executed")){ %> selected="selected" <%} %> >Executed Bookings</option>
<option value="cancelled" <%if(select.equalsIgnoreCase("Cancelled")){ %> selected="selected" <%} %> > Cancelled Bookings</option>
<option value="cancelReq" <%if(select.equalsIgnoreCase("cancelReq")){ %> selected="selected" <%} %> >Cancellation Requests</option>

</select>
<input type="submit" value="show">
</form>
</div>




 <div>
    <liferay-ui:search-container delta="10" emptyResultsMessage="Sorry. There are no items to display." iteratorURL="<%=iteratorURL%>">
        <liferay-ui:search-container-results  total="<%=bookingInfo.size()%>"
            results="<%=ListUtil.subList(bookingInfo, searchContainer.getStart(), searchContainer.getEnd())%>" />
        <liferay-ui:search-container-row modelVar="info" className="BookingInfo">
            <liferay-ui:search-container-column-text name="Booking Id" property="bookingId"/>
            <liferay-ui:search-container-column-text name="Car Type" property="carType"/>
            <liferay-ui:search-container-column-text name="Email Id" property="emailId"/>
            <liferay-ui:search-container-column-text name="Pick Up Date & Time" value="<%= info.getDateOut() + \"  \" + info.getTimeOut() %>"/>
            <liferay-ui:search-container-column-text name=" Drop Off Date & Time" value="<%= info.getDateDueIn() + \"  \" + info.getTimeDueIn() %>"/>
            <liferay-ui:search-container-column-text name=" Actual Drop Off Date & Time" value="<%= info.getDateIn() + \"  \" + info.getTimeIn() %>"/>
           
            <liferay-ui:search-container-column-text name="Status" property="carStatus"/>
       
            <liferay-ui:search-container-column-text name="Amount" value="<%=\" $ \"  + info.getAmount() %>"/>
       
        <%
            if(select.equalsIgnoreCase("cancelReq")){
        %>
        <liferay-ui:search-container-column-jsp path="/html/Admin/bookingdetail/actionBookingDetails.jsp" name="Action">
            </liferay-ui:search-container-column-jsp>
       
        <%}%>
       
        </liferay-ui:search-container-row>
        <liferay-ui:search-iterator searchContainer="<%=searchContainer%>" />
    </liferay-ui:search-container>           
   
</div>

Friday, 19 December 2014

Change Password Logic



public void changePassword(ActionRequest actionRequest,
            ActionResponse actionResponse) throws IOException, PortletException {

        String oldPassword = actionRequest.getParameter("oldPassword");
        String newPassword = actionRequest.getParameter("newPassword");
        String confirmPassword = actionRequest.getParameter("confirmPassword");
       
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

        User user = themeDisplay.getUser();
        String email = user.getEmailAddress();
       
        boolean sendMail = false;
       
        try {
           
            RegCustomer regCustomer = RegCustomerLocalServiceUtil.getRegCustomer(email);
            if(regCustomer.getPassword().equals(oldPassword)){           
            regCustomer.setPassword(newPassword);
           
            UserServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);
           
            regCustomer = RegCustomerLocalServiceUtil.updateRegCustomer(regCustomer);
            sendMail = true;
            }
           
         else if(!regCustomer.getPassword().equals(oldPassword)){
                SessionMessages.add(actionRequest, "request_processed", "Wrong Old Password");
            }

        } catch (Exception e) {
            try {
                BusinessUser businessUser =  BusinessUserLocalServiceUtil.getBusinessUser(email);
                if(businessUser.getPassword().equals(oldPassword)){
                businessUser.setPassword(newPassword);
               
                UserServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);
               
                BusinessUserLocalServiceUtil.updateBusinessUser(businessUser);
                sendMail = true;
                }
                  else if(!businessUser.getPassword().equals(oldPassword)){
                    SessionMessages.add(actionRequest, "request_processed", "Wrong Old Password");
                }
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }