Sunday, July 7, 2013

Few things about liferay search container



Some brief information about <liferay-ui:search-container/> tag attributes.



          <liferay-ui:search-container

       emptyResultsMessage="enter-or-refine-query-to-search-students"

                  headerNames="firstName,lastName,emailAddress"

                  iteratorURL="<%= portletURL %>"

                  orderByCol="<%= orderByCol %>"

                  orderByType="<%= orderByType %>"

                  delta="<%= delta %>"

                  deltaConfigurable="<%= false %>"

                  rowChecker="<%= new RowChecker(renderResponse) %>" 

          > 

  • rowChecker  - If you want to use check box based search container you have to add “rowChecker” attribute in the <liferay-ui:search-container/> tag.
  • deltaConfigurable  - If you don’t want to include Items per page section in the search container, set “deltaConfigurable” attribute to false. By default it’s value is true.
  • emptyResultMessage  - If you want to display custom message when there is no result available, set “emptyResultMessage” attribute.



Fetching value of selected check boxes in action class.

             <liferay-ui:search-container-row
                         className="com.liferay.portal.model.User"

                         escapedModel="<%= true %>"

                         keyProperty="userId"

                         modelVar="user2"

              >

Set "keyProperty" attribute in <liferay-ui:search-container-row> tag. & use below code in the action class.

String[] rowIds = ParamUtil.getParameterValues(actionRequest, "rowIds");

It will return an array of values selected from the search container. The array will have values which you will set as a ”keyProperty” value in <liferay-ui:search-container-row/>.

Setting custom value to search container check boxes


By default whatever value you will set for attribute “keyProperty” of <liferay-ui:search-container-row/> it will be assigned the value of check boxes, but if you want to set custom value to check boxes, addd “rowVar” attribute inside <<liferay-ui:search-container-row/> tag & then set the value with the help of setPrimaryKey() function of ResultRow clas.



<liferay-ui:search-container-row

                         className="com.liferay.portal.model.User"

                         escapedModel="<%= true %>"

                         keyProperty="userId"

                         modelVar="user2"

                         rowVar="curRow"

               > 

<% curRow.setPrimaryKey(user2.getFirstName() + StringPool.PIPE

                     + user2.getMiddleName() + StringPool.PIPE + user2.getLastName());

               %>

It will make value of check boxes like “userFirstName|userMiddleName|userLastName”.


Getting value of selected check boxes inside aui function.


Liferay.provide(

                           window,

                           '<portlet:namespace />deleteEntries',

                            function() {
                                       var cmd = 
                                              Liferay.Util.listCheckedExcept(
                                                  document.<portlet:namespace />fm,   "<portlet:namespace />allRowIds");
                             },

                             ['liferay-util-list-fields']

              );

In the above code block value of “cmd” parameter is comma separated value of selected check boxes.

Saturday, June 1, 2013

Submitting the parent form from liferay pop up window

Hi friends, sometimes in liferay after doing our stuff in the pop up window we want to send data back to parent form & submit it. So following are few steps to perform this task.

Call the following function on click of save button in liferay pop up window

<script type="text/javascript">
         
        AUI().ready('aui-dialog', function(A) {

               A.one('#<portlet:namespace />save').on('click', function() {

                              var comment = A.one('#<portlet:namespace/>declineCommentPopUp').val();

var declineComment  = Liferay.Util.getOpener().document.getElementById('<portlet:namespace />declineComment');

                              declineComment.value = comment;

Liferay.Util.getOpener().document.getElementById('<portlet:namespace />fm').action  =  '<%=declineAgreement%>';

                              Liferay.Util.getOpener().document.forms['<portlet:namespace />fm'].submit();

               });

});

</script>

In the above mentioned function 'declineCommentPopUp' & 'declineComment' are the fields available inside the form on the pop up & on the parent form respectively. '<portlet:namespace />fm' is the parent form. With the help of syntax

Liferay.Util.getOpener().document.getElementById('idOfElementOnParentForm');

we are able to access elements from the parent form & syntax

Liferay.Util.getOpener().document.forms['<portlet:namespace />fm'].submit(); 

will submit the parent form & close the pop up window.