Liferay Auto fields
The following example gives you the information
about how to use liferay auto fields in liferay development.
Life ray auto fields concept provides you can add
multiple input fields dynamically to the form.
Means if you want add multiple input fields to the
form based on user choice.
Download Auto field portlet from following location
Note:
Portlet developed in Liferay 6.1GA2 EE
version
If you want deploy in CE version you just do changes
in liferay-plugin-package.properties
Liferay
6.1 EE version
name=LiferayAutoFields
module-group-id=liferay-ee
module-incremental-version=1
tags=
short-description=
change-log=
page-url=http://www.liferay.com
author=Liferay, Inc.
licenses=EE
liferay-versions=6.1.20
|
Liferay
6.1 CE version
name= LiferayAutoFields
module-group-id=liferay
module-incremental-version=1
tags=
short-description=
change-log=
page-url=http://www.liferay.com
author=Liferay,
Inc.
licenses=LGPL
liferay-versions=6.1.1
|
Example:
Adding multiple phone numbers
Adding multiple addresses
Add multiple images or document
When we get above requirement we can use auto fields.
Here we have to identify which fields you want make
it multiple times such fields you have to wrap into particular div or field set.
We have to provide that element id to the auto filed script so that when we
click add button that wrapper content will be cloned.
At time of clones all names and ids of fields will
become unique.
The
following g is example code for auto fields
Add
following script in jsp page
<%@page
import="javax.portlet.ActionRequest"%>
<%@
include file="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>
|
Add
following AUI java script in jsp page.
<aui:script use="liferay-auto-fields">
new Liferay.AutoFields(
{
contentBox: '#phone-fields',
fieldIndexes: '<portlet:namespace />phonesIndexes'
}
).render();
</aui:script>
|
Add
following code in Action class
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);
}
}
|
Screen
1
Screen 2 out put in console:
Is it possible to start fieldindex from particulat digit? For eg i want to start row index from 6,7,8,9... and so on. then is it possible?
ReplyDeleteBy and large, you will be given modest auto protection as a result of the way that you will give the organization the entirety of your business. dealer-branded
ReplyDeleteTrailers are used to carry the motor cycles and generally the trailers may be of open or enclosed type and it is designed to haul the vehicles.Trailers are used to carry the motor cycles and generally the trailers may be of open or enclosed type and it is designed to haul the vehicles. When you buy the trailers for sale, you should be aware of the general information about the trailers and trailer services. The term enclosed trailer may refer to any number of different utility trailers. تعمیر درب ریموتی پارکینگ
ReplyDeleteThe website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface. w88kpi
ReplyDelete