Saturday, 14 July 2012

How to create new site programmaticly in liferay with validation

Create site in liferay

<%@page import="javax.portlet.PortletPreferences"%>
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@page import="com.liferay.portal.kernel.util.HtmlUtil"%>
<%@page import="com.liferay.portal.kernel.util.StringPool"%>
<%@page import="com.liferay.portal.kernel.util.UnicodeProperties"%>
<%@page import="com.liferay.portal.service.LayoutSetPrototypeServiceUtil"%>
<%@page import="com.liferay.portal.model.LayoutSetPrototype"%>
<%@page import="com.liferay.portal.service.GroupLocalServiceUtil"%>
<%@page import="java.util.List"%>
<%@page import="com.liferay.portal.kernel.bean.BeanParamUtil"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portal.model.Group"%>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/theme"  prefix="theme"%>
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
 <%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>

<portlet:defineObjects />
<theme:defineObjects/>

<%

PortletPreferences commonpref = renderRequest.getPreferences();
String commonvalue = (String)commonpref.getValue("commonvalue", "Hello! Welcome to our portal.");
//Group group = (Group)request.getAttribute("site.group");
//Group liveGroup = (Group)request.getAttribute("site.liveGroup");
LayoutSetPrototype layoutSetPrototype = (LayoutSetPrototype)request.getAttribute("site.layoutSetPrototype");
//boolean showPrototypes = GetterUtil.getBoolean(request.getAttribute("site.showPrototypes"));

long companyid=company.getCompanyId();
String languageid=user.getLanguageId();



long liveGroupId = 0;
//Group group = (Group)request.getAttribute(WebKeys.);
List<Group> objgroup=GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount());
Group group=objgroup.get(0);
long groupId = BeanParamUtil.getLong(group, request, "groupId");

System.out.println("Here are group :"+group);
Group stagingGroup = null;

Group liveGroup = null;

if (group != null) {
    if (group.isStagingGroup()) {
        liveGroup = group.getLiveGroup();

        stagingGroup = group;
    }
    else {
        liveGroup = group;

        if (group.hasStagingGroup()) {
            stagingGroup = group.getStagingGroup();
        }
    }
}
    liveGroupId = liveGroup.getGroupId();
    System.out.println("Here are livegroup id :"+liveGroupId);
    request.setAttribute("group", group);
%>
<%=commonvalue %>
<portlet:actionURL var="creatURL" name="Create">
<portlet:param name="viewJSP" value="/html/business/view.jsp"></portlet:param>

</portlet:actionURL>

<aui:form action="<%=creatURL %>" method="post">

<liferay-ui:error key="sitename" message="The site you has enter already eits" />
<aui:input name="commonvalue" type="hidden" value="<%=commonvalue %>"/>
<aui:input name="liveGroupId" type="hidden" value="<%=liveGroupId%>" />
<aui:input name="companyid" type="hidden" value="<%=companyid%>" />
<aui:input name="languageid" type="hidden" value="<%=languageid%>" />
<aui:input name="groupId" type="hidden" value="<%= groupId %>" />
<aui:input name="group" type="hidden" value="<%= group %>" />
<aui:input name="sitename" label="Enter Site" type="text" value="">
<aui:validator name="required"></aui:validator></aui:input>
<aui:input name="discription" label="Enter site discription" type="textarea" value="">
</aui:input>



 <aui:button type="submit" value="Create site" ></aui:button>
 


                           

                               
</aui:form>



Here are action file


package com.business.awaz;

import java.io.IOException;
import java.util.List;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletModeException;
import javax.portlet.ReadOnlyException;
import javax.portlet.ValidatorException;
import javax.portlet.WindowStateException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.UnicodeProperties;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.LayoutConstants;
import com.liferay.portal.model.LayoutSet;
import com.liferay.portal.model.LayoutSetPrototype;

 import com.liferay.portal.service.GroupServiceUtil;

import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.LayoutServiceUtil;
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.LayoutSetPrototypeServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;

import javax.portlet.PortletPreferences;
//import com.liferay.portlet.sites.util.SitesUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;



/**
 * Portlet implementation class Business
 */
public class Business extends MVCPortlet {
    public void fiveplan(ActionRequest fiveplanrequest,ActionResponse fiveplanresponse) throws ReadOnlyException, ValidatorException, IOException, PortletModeException, WindowStateException
    {
        String fiveplane=fiveplanrequest.getParameter("basicplan");   
       
        PortletPreferences fiveplanpref=fiveplanrequest.getPreferences();
                
        if(fiveplane !=null)
        {
            fiveplanpref.setValue("commonvalue", fiveplane);
            fiveplanpref.store();   
           
            fiveplanresponse.setRenderParameter("jspPage","/html/business/createsite.jsp");
           
        }


    }
   
       
   
    public void Create(ActionRequest actionRequest ,ActionResponse res) throws Exception
    {
           
        try {
            String sitename=actionRequest.getParameter("sitename");
             String findsitename="";
              List<Group> siteobj=GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount());
                for(int k=0;k<siteobj.size();k++)
                {
               
                    if(sitename.equals(siteobj.get(k).getName()))
                    {
                        //SessionErrors.add(actionRequest, "sitename");
                        findsitename=siteobj.get(k).getName();
                    }
           
                }
             String commonvalue=actionRequest.getParameter("commonvalue");

                long liveGroupId = Long.parseLong(actionRequest.getParameter("liveGroupId"));
                long companyid=Long.parseLong(actionRequest.getParameter("companyid"));
                String languageid=actionRequest.getParameter("languageid");
                String discription=actionRequest.getParameter("discription");
                System.out.println("Here is domain name"+sitename);
                System.out.println("Here is group name"+liveGroupId);
                int type = ParamUtil.getInteger(actionRequest, "type");
                String friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
                System.out.println("Friendlay URL is :"+friendlyURL);
                ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);
                Group liveGroup = null;
                String oldFriendlyURL = null;
                String oldStagingFriendlyURL = null;
                long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
                long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");
                System.out.println("Here are private id: :"+privateLayoutSetPrototypeId);
                System.out.println("Here are public id: :"+publicLayoutSetPrototypeId);
                System.out.println("Here are servicecontext id: :"+serviceContext);
                ServiceContext serviceContexta = new ServiceContext();
                Group liveGroups = null;
                       
               List<LayoutSetPrototype> layoutSetPrototypes = LayoutSetPrototypeServiceUtil.search(companyid, Boolean.TRUE, null);
                            String uuid=null;
                            for (LayoutSetPrototype curLayoutSetPrototype : layoutSetPrototypes)
                                {
                                UnicodeProperties settingsProperties = curLayoutSetPrototype.getSettingsProperties();
                                String servletContextName = settingsProperties.getProperty("customJspServletContextName", StringPool.BLANK);
                                String name=HtmlUtil.escape(curLayoutSetPrototype.getName(languageid));
                                System.out.println("hi this is :"+ curLayoutSetPrototype.getLayoutSetPrototypeId());
                   
                                  if(commonvalue.equals(name))
                                      {
                                    uuid=  curLayoutSetPrototype.getUuid();
                                      }
                                      name="";
                                }
                                 
                                  if(!uuid.equals(""))
                                  {
                                        
                                     if(findsitename.equals(""))       
                                     
                                     {                                   
                                    GroupServiceUtil.addGroup(sitename,discription, 1, friendlyURL, true, true ,serviceContext);

                                    Group groupobj=GroupLocalServiceUtil.fetchGroup(companyid, sitename);
                                    long groupid=groupobj.getGroupId();
                                   System.out.println("Site is creates");
                                   LayoutSet layoutsets=LayoutSetLocalServiceUtil.getLayoutSet(groupid,false);
                           
                                   layoutsets.setLayoutSetId(layoutsets.getLayoutSetId());
                                   layoutsets.setGroupId(layoutsets.getGroupId());
                                   layoutsets.setCompanyId(layoutsets.getCompanyId());
                                   layoutsets.setCreateDate(layoutsets.getCreateDate());
                                   layoutsets.setModifiedDate(layoutsets.getModifiedDate());
                                   layoutsets.setPrivateLayout(layoutsets.getPrivateLayout());
                                   layoutsets.setLogo(layoutsets.getLogo());
                                   layoutsets.setLogoId(layoutsets.getLogoId());
                                   layoutsets.setThemeId(layoutsets.getThemeId());
                                   layoutsets.setColorSchemeId(layoutsets.getColorSchemeId());
                                   layoutsets.setWapThemeId(layoutsets.getWapThemeId());
                                   layoutsets.setWapColorSchemeId(layoutsets.getWapColorSchemeId());
                                   layoutsets.setCss(layoutsets.getCss());
                                   layoutsets.setPageCount(1);
                                   layoutsets.setSettings(layoutsets.getSettings());
                                   layoutsets.setLayoutSetPrototypeUuid(uuid);
                                   layoutsets.setLayoutSetPrototypeLinkEnabled(true);
                               
                                   LayoutSetLocalServiceUtil.updateLayoutSet(layoutsets);
       


                           
                                   boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
                                   long parentLayoutId = ParamUtil.getLong(actionRequest, "parentLayoutId");
                                   String name1 = ParamUtil.getString(actionRequest, "name", "home");
                                   String title = StringPool.BLANK;
                                  String description = StringPool.BLANK;
                         
                                   boolean hidden = false;
                                   String friendlyURL1 = StringPool.BLANK;
                           

                                   ServiceContext serviceContext1 = ServiceContextFactory.getInstance(actionRequest);
                                   System.out.println("Service cintext is "+serviceContext1);
                           
                                   System.out.println("Here are new site id"+groupid);
                   
                                  LayoutServiceUtil.addLayout(groupid, false ,parentLayoutId ,name1 ,title ,description ,LayoutConstants.TYPE_PORTLET ,false ,friendlyURL1,serviceContext);
                                  res.setRenderParameter("jspPage", "/html/business/createsite.jsp");
                           
                                         }
                                    else
                                    {
                                   
                                    SessionErrors.add(actionRequest, "sitename");
                                  
                                   
                                    }
                                             
                                        
                                  }
       
             }
        catch (SystemException e) {
            // TODO Auto-generated catch block
                            e.printStackTrace();
        }   
       
    }
   
}

Friday, 15 June 2012

Crud Operation in Vaddin Portlet


Crud Operation on Vaadin portlet

Lets connect vaadin portlet with mysql database :
put poretal-ext.properties file under class file with following code

jdbc.default.driverClassName=com.mysql.jdbc.Driver

jdbc.default.url=jdbc:mysql://localhost:3306/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false

jdbc.default.username=root

jdbc.default.password=root





// this code will write under
public class DemoVaadinApplication extends Application {

String dbUrl = "jdbc:mysql:///lportal";
String dbClass = "com.mysql.jdbc.Driver";
Connection con = DriverManager.getConnection(dbUrl, "root","root");







How to insert data into mysql database table

Here are complete code for inserting data into vadin table






public class DemoVaadinApplication extends Application {

String dbtime;
String dbUrl = "jdbc:mysql:///lportal";
String dbClass = "com.mysql.jdbc.Driver";
@Override
public void init() {
final Window window = new Window();
final TextBox md=new TextBox(“Name”);
final TextBox name=new TextBox(“Fname”);


public void buttonClick(ClickEvent event) {
try {
String valu=(String)md.getValue();
String valu1=(String)name.getValue();

try {
Connection con1 = DriverManager.getConnection(dbUrl, "root","root");
System.out.println("Hi this is insert query:");

Statement st=con1.createStatement();
String mda="insert into vadin(name,fname)values('"+valu+"','"+valu1+"')";
int i=st.executeUpdate(mda);
if(i!=0)
{
System.out.println("Data is inserted");
}
else
{
System.out.println("Faile");
}
//qcSQL1.close();

}
catch(SQLException e) {
e.printStackTrace();
}

System.out.println("Click event value"+valu);
} catch (Exception e) {
// Ignored, we'll let the Form handle the errors
}
}
});
window.addComponent(save);
}
}





How to Develop Vaadin Portlet


Vaadin Portlet



The core piece of the Vaadin Framework is the Java library that is designed to make creation and maintenance of high quality web-based user interfaces easy. Here We are going to develop Vaadin portlet Using Eclips With liferay.
If you are already install ide in your eclips then only you have to add Vaadin.jar file in your plugin-packeg.properties
Other wise you have to install ide in our eclips and then add Vaadin.jar file in your plugin- packeg.properties.

Step to create vaadin portlet in liferay 6.1 :

Step 1:
Open eclips => file => new => liferay project =>Enter your project name(like demo_vaadin)=>next=>select radio button for vaadin portlet =>finish
Step 2 :
Now go to the rootfolder=>WEB-INF=>plugin-packeg.property=>add vaadin.jar file.



Step 3 :
Go to the sdk folder =>portlets=>open build.xml file now go the line 138
you will find the line......
<replacetoken><![CDATA[<name>view-jsp</name>]]></replacetoken>
replace this line by
<replacetoken><![CDATA[<name>view-template</name>]]></replacetoken>
and go to the line 129 and put following code
speed-filters-enabled=false
Step 4 :
Start your server if not already started and go to the ant build and deploy your project
now go the dock bar menu =>add=>more=>click on your demo_vaadin portlet your portlet will say Hello DemoVaadin!
Note :
In Vaadin portlet there is no use of jsp page .you will do every thing in action file which is find under docroot/WEB-INF/src/demo_vaadin. In this file init() is already created if you want to display any control(like imput box ,button ,form etc)then you have to write code under init()



Now lets Add imput box and button in our portlet


Wire following code under init() and deploy
public class DemoVaadinApplication extends Application {
@Override
public void init() {
final Window window = new Window(); //making object of main window
Label label = new Label("Hello DemoVaadin!");

window.addComponent(label);

final TextField tf = new TextField("Enter Name :");
tf.setValue("Initial content");
window.addComponent(tf);

setMainWindow(window); //this line set main window


}
}


1. if you want to display any message on your portlet then write following code under init()

Label label = new Label("Hello DemoVaadin!");

window.addComponent(label);

until you will not write window.addComponent(label) your message will not visible on your portlet.
2. for adding text box write following code

final TextField tf = new TextField("Enter Name :");
tf.setValue("Initial content");
window.addComponent(tf);







3. adding button in portlet
Button okbutton = new Button("OK");
window.addcomponent(okbutton);

Handling input box with button:

Here are code for handling input box using button:
Button show = new Button("Show", new Button.ClickListener() {
final TextField md = new TextField("Enter Name :");
md.setValue("Initial content");
window.addComponent(md);
public void buttonClick(ClickEvent event) {
String valu=(String)md.getValue();//getting value of input box

System.out.println(value);//when you click on show button you will get input value of your input box on comsole
window.addComponent(show);

How date and time will display whwn you click on display time button

Here is complete code for this:
new Button("What is the time?",
new Button.ClickListener() {
//@Override
public void buttonClick(ClickEvent event) {
// TODO Auto-generated method stub
window.showNotification(
"The time is " + new Date());
}
}));







Friday, 18 May 2012

service builder with crud operation in liferay



  Crud and Search opration in Liferay:
 
   ->  Liferay use service builder techniq for Crud opration.
   ->  Service builder purform by  Service.xml file.
   ->  Service.xml file create table in database and also create class and diffrent method.
 
1)     Create service.xml file.
            ->Create service.xml file in WEB-INF and write below code.
            ->CODE:

       <service-builder package-path="com.test">  

      <namespace>qr</namespace> 

        <entity name="Searchclass" local-service="true"
                                       remote- service="false">  
          
            <column name="id" type="long" primary="true"/>    
             <column name="itemname" type="String" />      

            <finder name="Itemname" return-type="Collection"
               <finder-column name="itemname" />
            </finder>
       </entity>

   </service-builder>     


          #1Java package for code

          #2 Namespace for tables

          #3 Name of entity

          #4 Primary key

          #5 Additional fields

          #6 Finder methods

    
   ->Then after build service using cmd:
        ant build-service
   ->Then after compile process use cmd:
        ant compile
   -> Then deploy project:
        ant deploy

   -> In eclips use ant tool and click build-service tag.
        ->Then after refresh  project and click compile tag.
        ->Once again refresh project and deploy .
  



      ->When ant build-service run after that refresh project then see new folder and some new java file  is  created.
       ->Files and folder are define below image:


    ->In above two  image define two folder firsst one has service and second one has src which has  com/test/model , com/test/service folder . This all are created by ant build-service command.
     
    -> com/test/model/service/impl has file SearchclassLocalServiceImpm.java in which we create
      any method and use as service builder class  method.

   -> Create method and ant build-service,ant compile and refresh project. After that see created method in   file WEB-INF/service/com/test/service/SearchclassLocalserviceUtil.java  use for requiered purpos. 
   
    -> Use <finder> in service.xml and ant build-service,ant compile,the finder maethod is genrated in /WEB-INF/service/com/test/service/persistence/SearchclassPersistence.java .     



2)     How to add data in table:
     
       2.1)create .jsp page which display UI tag.
              ->Write code below :
  
 
      <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
       <%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
      <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
     
<portlet:defineObjects />

<portlet:actionURL name="Add" var="add" />

<aui:form name="a" action="<%=add.toString() %>" method="post" >

 <aui:input type="text" label="Name" name="nm" value="" />
 <aui:button type="submit" value="Save" />

</aui:form> 
           
    2.2) Make code for insert in /docroot/WEB-INF/src/com/test/NewPortlet.java
           ->Write below code :
  package com.test;

  import javax.portlet.ActionRequest;
  import javax.portlet.ActionResponse;
  import com.liferay.counter.service.CounterLocalServiceUtil;
  import com.liferay.util.bridges.mvc.MVCPortlet;
  import com.test.model.Searchclass;
  import com.test.model.impl.SearchclassImpl;
  import com.test.service.SearchclassLocalServiceUtil;

  public class NewPortlet extends MVCPortlet {
         public void Add(ActionRequest ar , ActionResponse aq) throws Exception
                {
                               String str=ar.getParameter("nm");
              
     //Auto increament primary key.  
        long l=  CounterLocalServiceUtil.increment(Searchclass.class.getName());
                                    
     // Service.xml create class which instance declare usinf *Imlp()

                      Searchclass ins=new SearchclassImpl();
                    
                      ins.setId(l);
                   
                      ins.setItemname(str);

       // Add entry in table
                     SearchclassLocalServiceUtil.addSearchclass(ins);

                  }
           }

       ->In above code has “Add” method which is define in <portlet:actionURL name="Add" var="add" /> in .jsp page.

    -> <portlet:actionURL> find “Add” method in Action file and execute it.

3)     Update,delete and Display Entry

     -> Use Search container for Display data and also use Delete and Update
        data.
    
     -> Search container code for Display data and Button for delete and update.
     -> Write Code in Jsp Page:
        
          Code:    

 <liferay-ui:search-container delta="5" emptyResultsMessage="no-users-were-found">
               <liferay-ui:search-container-results>
               <%
               List<Searchclass> tempResults = SearchclassLocalServiceUtil.getSearchclasses(0,SearchclassLocalServiceUtil.getSearchclassesCount());
               results = ListUtil.subList(tempResults, searchContainer.getStart(),    searchContainer.getEnd());
               total = tempResults.size();
               pageContext.setAttribute("results", results);
               pageContext.setAttribute("total", total);
              
               %>
               </liferay-ui:search-container-results>   
                  
               <liferay-ui:search-container-row className="com.test.model.Searchclass" keyProperty="id" modelVar="item">

   //This tag dispaly table data
                
                               <liferay-ui:search-container-column-text name="itemname" value="<%=item.getItemname() %>"/>
  
      //This tag display Buttton Which is assign Jsp page.
                               
                               <liferay-ui:search-container-column-jsp  path="/html/newportlet/button.jsp" align="right"/>
                             
                             
                               </liferay-ui:search-container-row>

                 <liferay-ui:search-iterator />

     </liferay-ui:search-container>

       
   ->For button in search container, first create jsp page for button and also
     Create method for button event like update,delete otherwise it genrate 
     Error. Let see code below.

   ->For button create jsp page which assing in service builder
        <liferay-ui:search-container-column-jsp          path="/html/newportlet/button.jsp" align="right"/>   

   


  ->button.jsp page code:
 
   <%
 ResultRow rslt=(ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
 Searchclass img=(Searchclass)rslt.getObject();
 String prk=String.valueOf(img.getPrimaryKey());
%>

//Button menu tag
<liferay-ui:icon-menu>

  //Create “editProduct” method in Action file for Redirect update form page
        <portlet:actionURL name="editProduct" var="editURL">
       <portlet:param name="key" value="<%=prk%>" />
       </portlet:actionURL>

  // ”EDIT” button for Update event. 
       <liferay-ui:icon image="edit" message="Edit" url="<%=editURL.toString() %>" /> 
 
 // Create “deleteProduct” method in Action file for DELETE
          <portlet:actionURL name="deleteProduct" var="deleteURL">
          <portlet:param name="key" value="<%= prk %>" />
          </portlet:actionURL>

  //”DELETE” Button for DELETE Event
         <liferay-ui:icon-delete url="<%=deleteURL.toString() %>" />
      
</liferay-ui:icon-menu>


   ->After this create method  in Action file which define in code.
         1> editProduct
         2> deleteProduct

    ->Code for Event:

  3.1>For Update code:
   public void editProduct(ActionRequest ar,ActionResponse ap) throws Exception
     {
                String str= ar.getParameter("key");
                long l=Long.valueOf(str);
                                            
       //Retriev table data using Primary key
                
       Searchclass a=SearchclassLocalServiceUtil.getSearchclass(l);
                                            
       //Set Attribute which has all values of specified pk.
                ar.setAttribute("edit",a );
     
      // Redirect to Jsp page which has Update form. 
                ap.setRenderParameter("jspPage","/html/newportlet/edit.jsp");
                                            
      }

     -> Now Create Jsp page which is Update form.Here is edit.jsp Page

   



     -> code fro edit.jsp page:

 //get attribute for update which is fetch in Action file above.1

  <jsp:useBean id="edit" type="com.test.model.Searchclass" scope="request" /> 
 
 
  //Create “updateProductURL” method for Update.
  //”updateProductURL” is custmize method name.give any name. 
    <portlet:actionURL name="updateProductURL" var="updateProductURL"/>
   
   
   <aui:form  action="<%=updateProductURL.toString() %>" method="post"> 

     <aui:input name= "key" value="<%=edit.getPrimaryKey() %>" type="hidden" /> 
 
     <aui:input name="nm" label="name" value="<%=edit.getItemname() %>" size="45" />
    
     <aui:button type="submit" value="Save"/>
  
   
</aui:form> 
  
 
     -> “updateProductURL” method in Action File
  

public void updateProductURL(ActionRequest ar,ActionResponse ap)throws Exception
  {
     String str=ar.getParameter("nm");
     String str1=ar.getParameter("key");
     long l=Long.valueOf(str1);
 
     //Fetch data from table using pk
     Searchclass itm=SearchclassLocalServiceUtil.getSearchclass(l);
 
     //set update data
     itm.setItemname(str);

    // Update method with change data
     SearchclassLocalServiceUtil.updateSearchclass(itm);

        //Redirect to Search container with update entry
     ap.setRenderParameter("jspPage","/html/newportlet/view.jsp");
 }


  3.2>Delete code:
  
   ->Once create button for delete in jsp page then after create delete method
     in Action file.
   
   ->”deleteProduct” is method which is define in jsp page
        <portlet:ActionUrl var=” ” name=” deleteProduct”>
 
    ->Code is below.





  public void deleteProduct(ActionRequest ar,ActionResponse ap) throws Exception
    {
               String str= ar.getParameter("key");
               long l=Long.valueOf(str);
               SearchclassLocalServiceUtil.deleteSearchclass(l);
               ap.setRenderParameter("jspPage","/html/newportlet/view.jsp");
    }
              
                
 4)Search data.
  
  ->We can search data with all column entry Like Primary key,Name,item so on.

  ->In this example use itenname for searching data.

   ->First define finder in service.xml
   
   ->code :                                           

 
   <finder name="Itemname" return-type="Collection">
       <finder-column name="itemname" />
   </finder>
   
   ->Write This code in above </entity>

      1) <finder name="Itemname" return-type="Collection">

    ->name="Itemname" :-> is Finder method name which is genrated by
            ant sercive-build and ant compile time.

     ->Method called by persistence interface and called “Itemname” by         “findbyItemname”       

     ->return-type="Collection" :-> It is return List.

        2)<finder-column name="itemname" />
       
      ->It is define column name which use for search data by this column entry
 
   ->Now to make jsp page to display search form.

        1) Jsp page search.
         Code:

          // Assing ”search” method which is create in  Action file
 
             <portlet:actionURL var="asd"  name ="search" />

          // Search form
             <aui:form name="b" action="<%=asd.toString() %>" method="post" >
               <aui:input type="text" label="Name" name="nm" value="" />
               <aui:button type="submit" value="Search" />
             </aui:form>

      








       2)In Action file
         
         ->Create method which name is “search”
         ->Code :
           
   public void search(ActionRequest req,ActionResponse res) throws Exception
                {
                                              
                   String str = req.getParameter("nm");
                             
        //Set attributes for search result
                   req.setAttribute("nma",str);
     
        //Redirect search container to display result                   
                   res.setRenderParameter("jspPage","/html/newportlet/view.jsp");
                                                                                           
                }           
                 
          ->This code only redirect to search result jsp page with required attributes.

         ->Now we use *Impl.java file and also *persistence interface.

         ->In *Impl.java create custom method and use *persistence interface in  method for search data.

          -> Action file called customize method which is created in *Impl.java
and *Impl method called finder method by *persistence interface.

         ->Below code specified it. We display result in search container.

       1)Create search container in jsp page
          ->Code:

<liferay-ui:search-container delta="5" emptyResultsMessage="no-users-were-found" >
<liferay-ui:search-container-results

 //Call *impl customize method usin *LocalServiceUtil class
 // Method name is “searchbyuser”

  results="<%= SearchclassLocalServiceUtil.searchbyuser(str) %>"

//size of result
  total="<%= SearchclassLocalServiceUtil.searchbyuser(str).size()%>"         
               />
              
 //Create Instance of service builder class
                  
               <liferay-ui:search-container-row className="com.test.model.Searchclass" keyProperty="id" modelVar="itename">
              
 //Display Result               
                                            
                              <liferay-ui:search-container-column-text name="itemname" value="<%=itemname.getItemname() %>"/>
                               </liferay-ui:search-container-row>

                 <liferay-ui:search-iterator />

     </liferay-ui:search-container>

  -> Now let see how *Impl class work.
 
     1) Create method in *Impl.java file .
     
    ->  Code :

 public  List<Searchclass>  searchbyuser(String name) throws SystemException,PortalException
                {
                             
 // searchPersistence.findByItemname(name) method created by <finder> tag write in servicr.xml file.

 //Return search result in List<>
                    List<Searchclass> a= searchclassPersistence.findByItemname(name);
                               
          return a;
                
        }
              
      ->After that ant build-service and ant compile.

      ->This method is use by *LocalerviceUtil class.