Step 1 :
Create a portlet named as ‘Auto Fields’.
Step 2:
Create a folder structure named as
‘/html/autoFieldsPortlet’ under docroot of the created portlet.
Step 3 :
Create a jsp named as ‘init.jsp’
under ‘/html/ autoFieldsPortlet’ folder
structure and place the following code in it.
<%@page import="com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil"%>
<%@page import="com.liferay.portlet.asset.service.AssetTagLocalServiceUtil"%>
<%@page import="com.liferay.portlet.asset.model.AssetEntry"%>
<%@page import="com.liferay.portal.model.RoleConstants"%>
<%@page import="com.liferay.portal.service.RoleLocalServiceUtil"%>
<%@page import="com.liferay.portal.model.Role"%>
<%@page import="com.liferay.portal.model.Team"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.liferay.portal.service.TeamLocalServiceUtil"%>
<%@page import="com.liferay.portal.service.ResourcePermissionLocalServiceUtil"%>
<%@page import="com.liferay.portal.model.ResourcePermission"%>
<%@page import="com.liferay.portal.service.GroupLocalServiceUtil"%>
<%@ page import="javax.portlet.PortletPreferences" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<%@ page import="com.liferay.portal.kernel.util.WebKeys"
%>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil"
%>
<%@ page import="com.liferay.portal.kernel.language.LanguageUtil"
%>
<%@ page import="com.liferay.portal.kernel.bean.BeanParamUtil"
%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.MissingResourceException"
%>
<%@ page import="java.util.Properties" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.Stack" %>
<%@ page import="java.util.TimeZone" %>
<%@ page import="java.util.TreeMap" %>
<%@ page import="java.util.TreeSet" %>
<%@ page import="javax.portlet.MimeResponse" %>
<%@ page import="javax.portlet.PortletConfig" %>
<%@ page import="javax.portlet.PortletContext" %>
<%@ page import="javax.portlet.PortletException" %>
<%@ page import="javax.portlet.PortletMode" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<%@ page import="javax.portlet.PortletRequest" %>
<%@ page import="javax.portlet.PortletResponse" %>
<%@ page import="javax.portlet.PortletSession" %>
<%@ page import="javax.portlet.PortletURL" %>
<%@ page import="javax.portlet.RenderRequest" %>
<%@ page import="javax.portlet.RenderResponse" %>
<%@ page import="javax.portlet.ActionRequest"%>
<%@ page import="javax.portlet.ResourceURL" %>
<%@ page import="javax.portlet.UnavailableException"
%>
<%@ page import="javax.portlet.ValidatorException" %>
<%@ page import="javax.portlet.WindowState" %>
<%@ page import="com.liferay.portlet.PortletPreferencesFactoryUtil"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.liferay.portal.kernel.util.UnicodeFormatter"
%>
<%@ page import="com.liferay.portal.kernel.util.UnicodeProperties"
%>
<%@ page import="com.liferay.portal.kernel.util.Validator"
%>
<%@ page isELIgnored="false" %>
<script src="/html/js/liferay/service.js" type="text/javascript"></script>
<script src="/html/js/jquery/jquery.js" type="text/javascript"></script>
<script src="/html/js/jquery/json.js" type="text/javascript"></script>
<script src="/html/js/editor/ckeditor/ckeditor.js"
type="text/javascript"></script>
<portlet:defineObjects />
<liferay-theme:defineObjects/>
Step 4 :
Open the
liferay-plugin-package.properties file and import place the following code in it.
portal-dependency-jars=\
jstl-api.jar,\
jstl-impl.jar
portal-dependency-tlds=\
c.tld,\
liferay-aui.tld,\
liferay-faces.tld,\
liferay-portlet-ext.tld,\
liferay-portlet.tld,\
liferay-security.tld,\
liferay-theme.tld,\
liferay-ui.tld,\
liferay-util.tld
Step 5:
Create a jsp named as ‘view.jsp’
under ‘/html/ autoFieldsPortlet’ folder
structure and place the following code in it.
<%@page import="javax.portlet.ActionRequest"%>
<%@ include file="/html/tabsPortlet/init.jsp" %>
<portlet:actionURL var="editArticleActionURL"
windowState="<%=
WindowState.NORMAL.toString()%>">
<portlet:param name="<%=ActionRequest.ACTION_NAME%>"
value="getAutoFieldsData" />
</portlet:actionURL>
<h1>Liferay auto fields example</h1>
<aui:form action="<%=editArticleActionURL%>"
method="post" name="LiferayAautoFieldForm">
<div id="phone-fields">
<div class="lfr-form-row
lfr-form-row-inline">
<div class="row-fields">
<aui:input fieldParam='phoneNumber0'
id='phoneNumber0' name="phoneNumber0"
label="Phone Number" />
<aui:select id="phoneTypeId0"
name="phoneTypeId0" label="Type">
<aui:option value="11006" label="Business"></aui:option>
<aui:option value="11007" label="Business
Fax"></aui:option>
<aui:option value="11008" label="Mobile
Phone"></aui:option>
<aui:option value="11009" label="Other"></aui:option>
<aui:option value="11011" label="Personal"></aui:option>
</aui:select>
</div>
</div>
</div>
<aui:layout>
<aui:column>
<aui:button type="submit"
value="Save Phone Numbers" name="SavePhoneNumbers"
onClick="saveData();"></aui:button>
</aui:column>
</aui:layout>
<aui:script use="liferay-auto-fields">
new Liferay.AutoFields(
{
contentBox: '#phone-fields',
fieldIndexes: '<portlet:namespace />phonesIndexes'
}
).render();
</aui:script>
</aui:form>
Step 6 :
In portlet.xml change the view.jsp
path to the following code .
<init-param>
<name>view-jsp</name>
<value>/html/ autoFieldsPortlet /view.jsp</value>
</init-param>
Step 8 :
Create a package named as
‘com.autofields’.
Step 9 :
Create a class named as
‘AutoFields.java’ under the package of ‘com.autofields’ and place the following
code in it.
package com.autofields;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import
com.liferay.portal.kernel.util.ParamUtil;
import
com.liferay.portal.kernel.util.StringUtil;
import
com.liferay.util.bridges.mvc.MVCPortlet;
public class AutoFields extends MVCPortlet{
public void getAutoFieldsData(ActionRequest actionRequest,ActionResponse response)
throws Exception {
System.out.println("=============getAutoFieldsData==");
String phonesIndexesString =
actionRequest.getParameter(
"phonesIndexes");
System.out.println("=============phonesIndexesString=="+phonesIndexesString);
int[] phonesIndexes = StringUtil.split(phonesIndexesString, 0);
for (int phonesIndex : phonesIndexes) {
String number = ParamUtil.getString(actionRequest,
"phoneNumber" + phonesIndex);
System.out.println("=============phoneNumber=="+number);
int typeId = ParamUtil.getInteger(actionRequest,
"phoneTypeId" + phonesIndex);
System.out.println("=============typeId=="+typeId);
}
}
}
Step 10 :
In portlet.xml change the <portlet-class></portlet-class> path to the following code .
<portlet-class>com.autofields.AutoFields</portlet-class>
Step 11 :
Deploy the portlet and see the portlet in the website page.
No comments:
Post a Comment