Prasad
Prasad

Reputation: 686

How to pass the User entity results from action class to view.jsp

I have created a portlet where I am fetching the user details filtering the list based on some condition in my action class. Now how can I pass the results (List of users) from my action class to view.jsp?

my Action class code,

public void addEntry(ActionRequest request, ActionResponse response) throws PortalException, SystemException
{
int usersCount = UserLocalServiceUtil.getUsersCount();
            List<User> usersList = UserLocalServiceUtil.getUsers(0 , usersCount);
            System.out.println("List Size is ===>"+ usersList);
            if (usersList != null) {
            for (User user : usersList) {  
                            if(user.getFacebookId() == 12345 && user.getStatus() == 0)
                            {
                                    System.out.println(((Long) user.getUserId()).toString()+ "," + user.getFullName()+ "," + user.getFirstName()+ "," + user.getLastName()+ "," + user.getScreenName());

                            }
                }
            }

}

In my action class I am filtering the list based on FacebookID and user status. It is printing the required users list. Now How can I send the list of filtered users to my view page.

View page code,

<liferay-ui:search-container delta="10" emptyResultsMessage="no-users-were-found">
        <liferay-ui:search-container-results
                results="<%=UserLocalServiceUtil.getUsers(searchContainer.getStart(), searchContainer.getEnd())%>"
       total="<%=UserLocalServiceUtil.getUsersCount()%>" />


        <liferay-ui:search-container-row
                className="com.liferay.portal.model.User"
                keyProperty="userId"
                modelVar="user"
        >
                <liferay-ui:search-container-column-text
                        name="name"
                        value="<%= user.getFullName() %>"
                />

                <liferay-ui:search-container-column-text
                        name="first-name"
                        property="firstName"
                />
                <liferay-ui:search-container-column-text
                        name="last-name"
                        property="lastName"
                />
                <liferay-ui:search-container-column-text
                        name="screen-name"
                        property="screenName"
                />
        </liferay-ui:search-container-row>

        <liferay-ui:search-iterator />

</liferay-ui:search-container>

<liferay-ui:search-container delta="10" emptyResultsMessage="no-users-were-found" />

Any suggestions that How can I pass the filter list in action class to liferay-ui:search-container-results.

Thanks in advance.

Upvotes: 0

Views: 283

Answers (1)

Danish
Danish

Reputation: 913

    List<User> tempList = new ArrayList<User>();
    for (User user : usersList) {  
                                if(user.getFacebookId() == 12345 && user.getStatus() == 0)
                                {
                                  tempList.add(user);                                        
                                  System.out.println(((Long) user.getUserId()).toString()+ "," + user.getFullName()+ "," + user.getFirstName()+ "," + user.getLastName()+ "," + user.getScreenName());

                                }
     }
      actionRequest.setAttribute("userList",tempList);          

Put up the usersList in the request object from the Action Class by using actionRequest.setAttribute("userList",tempList); And also the user count in the same fashion. Now in the jsp just replace the following lines.

results="<%=request.getAttribute("userList")%>"
   total="<%=request.getAttribute("count")%>

Not sure you may need some type casting also on the above lines.

Upvotes: 1

Related Questions