Foren

Vaadin Lazy Query Container and Liferay Service Builder

thumbnail
Ivano Carrara, geändert vor 9 Jahren.

Vaadin Lazy Query Container and Liferay Service Builder

Expert Beiträge: 345 Beitrittsdatum: 03.07.05 Neueste Beiträge
Hi all,

I need a simple example to build a CRUD portlet for Liferay using Vaadin Lazy Query Container for the presentation of data and data persistence managed by Liferay's service layer.

Please, there is someone that can show us and example using Vaadin and services classes generated by Liferay's Service Builder ?

I know that there is a Lazy loader control to do that but no one explained how to link data returned from some sort of MyEntityLocalServiceUtil.getAllRecords(...) to a Vaadin control to paginate the data ...

I found many posts and blogs talking about the beauty of Vaadin and Liferay togheter but no example on the main integration a Liferay portlet developer need.

Thank you for any comments on this !

Ivano C.
thumbnail
David H Nebinger, geändert vor 9 Jahren.

RE: Vaadin Lazy Query Container and Liferay Service Builder

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
You would follow directions basically like found here.

That example builds a custom query, whereas for SB binding I'd keep the values around and use as flags for invoking the correct finder method.

The size() method override would call the appropriate SB method to return the query count, and the loadItems method would invoke the similar paged query from the SB API.

For example, to handle all Liferay users you'd probably do something like:

package com.dnebinger.example;

import java.util.ArrayList;
import java.util.List;

import org.vaadin.addons.lazyquerycontainer.Query;
import org.vaadin.addons.lazyquerycontainer.QueryDefinition;

import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItem;

import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;

public class LiferayUserQuery implements Query {

        private EntityManager entityManager;
        private QueryDefinition definition;
        
        public MovieQuery(EntityManager entityManager, QueryDefinition definition,
                                Object[] sortPropertyIds, boolean[] sortStates) {
                super();
                this.entityManager = entityManager;
                this.definition = definition;

                // ...
        }

        @Override
        public Item constructItem() {
                return new BeanItem<user>(UserLocalServiceUtil.createUser(0));
        }

        @Override
        public int size() {
                return (int) UserLocalServiceUtil.getUsersCount();
        }

        @Override
        public List<item> loadItems(int startIndex, int count) {
               List<user> users = null;

                try { users=UserLocalServiceUtil.getUsers(startIndex, startIndex+count); } catch (...)

                List<item> items = new ArrayList<item>(users.size());

                for (User user : users) {
                         items.add(new BeanItem<user>(user));
                }
                
                return items;
        }

        @Override
        public void saveItems(List<item> addedItems, List<item> modifiedItems,
                        List<item> removedItems) {
                throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean deleteAllItems() {
                throw new UnsupportedOperationException();
        }
}</item></item></item></user></item></item></user></item></user>


Now this is a contrived example that I simply wouldn't put into production... First, the User object has a lot of stuff in it, most of what you don't need to keep around in your bean items. I'd use some sort of transient user class to thin out what isn't needed by the front end.

Second, the bean items will not resolve any foreign key references and do other translations from codes to display values, so it's yet another reason to use a transient user class that is more display friendly.

Third, I didn't deal with sorting and/or filters in any way. Not that it's hard to do in general, but for users well it just isn't supported (I mean, all you get is the single getUsers() method, there aren't alternatives for filtering and no way to indicate sort outside of what the entity definition is). For your own custom entities, you can expose this information (personally I'd probably build method(s) in my CustomEntityLocalServiceImpl that I passed in a similar set of arguments the lazy loader gives you and build the method(s) to handle the right invocation of your finders or dynamic queries or what not).

Finally, I would note that the lazy loader is not a panacea. First, any table with a lot of rows in it can potentially be called upon to lazy load all of them, and you must remember that all objects lazily loaded will remain bound in the user session until purged. Multiplying by the number of users that will have access to this table and be online at the same time, it should become obvious that this may lead to a drain of all of your server side resources.

Basically what I'm saying is that all implementation decisions come with consequences, and you should at least try to be aware of the consequences and make an educated decision about whether you can live with those consequences.
thumbnail
Ivano Carrara, geändert vor 9 Jahren.

RE: Vaadin Lazy Query Container and Liferay Service Builder

Expert Beiträge: 345 Beitrittsdatum: 03.07.05 Neueste Beiträge
Dear David, I just sent an email to support AT vaadinonliferay.com with questions about your great Vaadin 7 Control Panel plugin in Liferay's Marketplace.

Thank you in advance for any comments !

Ivano C.
thumbnail
David H Nebinger, geändert vor 9 Jahren.

RE: Vaadin Lazy Query Container and Liferay Service Builder

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
Sent a reply this morning, hopefully you got it.
thumbnail
Jack Bakker, geändert vor 9 Jahren.

RE: Vaadin Lazy Query Container and Liferay Service Builder

Liferay Master Beiträge: 978 Beitrittsdatum: 03.01.10 Neueste Beiträge
This is as exciting as slow television. (it is a very cool Control Panel app tho...)