Today we will see how to use Liferay Auto Fields. We can create fields at run time by using this. So lets Start:-
Inside your jsp paste this:-
view.jsp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> | |
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %> | |
<portlet:defineObjects /> | |
<portlet:actionURL name="save" var="saveURL"></portlet:actionURL> | |
<aui:form action="<%=saveURL %>" method="post" name="fm"> | |
<div id="auto-fields-container"> | |
<div class="lfr-form-row lfr-form-row-inline"> | |
<aui:input label="phone-number" name="phone1" required="true"/> | |
</div> | |
</div> | |
<aui:button-row> | |
<aui:button type="submit" value="save" /> | |
</aui:button-row> | |
</aui:form> | |
<aui:script> | |
AUI().use('liferay-auto-fields',function(A) { | |
new Liferay.AutoFields( | |
{ | |
contentBox: '#auto-fields-container', | |
fieldIndexes: '<portlet:namespace />rowIndexes', | |
on: { | |
'clone': function(event) { | |
//alert("-- Add --"); | |
}, | |
'delete': function(event) { | |
//alert("-- Delete --"); | |
} | |
}, | |
sortable: true, | |
} | |
).render(); | |
}); | |
</aui:script> |
Explanation:-
1)Here we create a text box phone number which can be repeated by Clicking '+' and delete by clicking '-'.
2)On Add clone function is called.
3)On Subtract delete function is called.
4)When we Click save we can get the values by :-
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { | |
String rowIndexes = request.getParameter("rowIndexes"); | |
String[] indexOfRows = rowIndexes.split(","); | |
for (int i = 0; i < indexOfRows.length; i++) { | |
String phone = (request.getParameter("phone"+ indexOfRows[i])).trim(); | |
System.out.println("Phone=>"+phone); | |
} | |
} | |
Output:-
Hope this will Help....
Related Post:-
No comments:
Post a Comment