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.

1 comment: