hook - Dynamically Display liferay-search-container columns based on Arraylist? -


i trying display columns of liferay grid dynamically. same reason reference suggestion following link, dynamic columns in liferay-ui:search-container?, giving option user selected required columns of table in configuration page. selected columns of config page saving in array list.

issue: need display columns based on array list values. instead hard coding column properties need iterate list , display selected column in table/grid.

let's assume working on liferay default user_ model. selected columns of config page saving in 1 list follows,

arraylist<string> al = new arraylist<string>();     iterator<string> itr = al.iterator();     while(itr.hasnext())     {             string columnname = itr.next();             columnname = columnname.trim().tolowercase();              string columnval = portletpreferences.getvalue(columnname, stringpool.blank);        al.add(columnname);     } 

now let's assume user has selected following columns in config page {first name, last name, screen name}. list contain these 3 values.

based on elected columns need dynamically create columns [ <liferay-ui:search-container-column-text>] in search container.

<liferay-ui:search-container delta="5" emptyresultsmessage="no-users-were-found">         <liferay-ui:search-container-results                  results="<%= listutil.sublist(users, searchcontainer.getstart(),searchcontainer.getend()) %>"         total="<%= totalnoofusers %>">         </liferay-ui:search-container-results>     <liferay-ui:search-container-row classname="com.liferay.portal.model.user" keyproperty="userid"        modelvar="user">        </liferay-ui:search-container-row>        <liferay-ui:search-iterator />  </liferay-ui:search-container> 

how can create columns hard coding follows,

<liferay-ui:search-container-column-text name="last name" value="<%= user.getlastname() %>">         </liferay-ui:search-container-column-text> 

need suggestions, in advance

you can use <c:foreach> or scriptlet for traverse arraylist of column names, follows:

here entrycolumns arraylist of columns saved.

<% for(string columnname : entrycolumns) { %>      <c:choose>         <c:when test='<%= "firstname".equals(columnname) %>'>             <liferay-ui:search-container-column-text name="first name"> value="<%= user.getfirstname() %>" />         </c:when>         <c:when test='<%= "lastname".equals(columnname) %>'>             <liferay-ui:search-container-column-text name="last name"> value="<%= user.getfirstname() %>" />         </c:when>         <c:when test='<%= "birthdate".equals(columnname) %>'>             <liferay-ui:search-container-column-text name="birth date">                 <fmt:formatdate value="<%= user.getbirthdate() %>" pattern="dd mmm yyyy" />             </liferay-ui:search-container-column-text>         </c:when>     </c:choose>  <% } %> 

if not fan of scriptlets can use like:

<c:foreach items="${entrycolumns}" var="columnname">     <c:choose>         <c:when test='${"firstname" eq columnname}'>             <liferay-ui:search-container-column-text name="first name"> value="<%= user.getfirstname() %>" />         </c:when>     </c:choose> </c:foreach> 

you need have checks columnname container text , value, since these different , in cases might want write html instead of using value attribute way takes care of well.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -