I am trying to display the columns of liferay grid dynamically. For the same reason with reference to some suggestion from the following link, Dynamic columns in liferay-ui:search-container?, I am giving an option to the user to selected required columns of the table in the configuration page. The selected columns of the config page are saving in the array list.
Issue: Now I need to display the columns based on the array list values. Instead hard coding the column properties I need to iterate the list and display the selected column in the table/grid.
Let's assume I am working on liferay default USER_ model. All the selected columns of the config page are saving in one list as 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 that the user has selected the following columns in the config page {First Name, Last Name, Screen Name}. So the list will contain only these three values.
Based on this elected columns I need to dynamically create the columns [ <liferay-ui:search-container-column-text>
] in the 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 I create the columns with hard coding as follows,
<liferay-ui:search-container-column-text name="Last Name" value="<%= user.getLastName() %>">
</liferay-ui:search-container-column-text>
Need some suggestions, Thanks in advance