Directory

← Back

Lazy Paged Container

A lazy paged container for minimal bandwidth

Author

Rating

Popularity

<100

Perfect is you want implement yours on filters but on your server.

A complete example on the source code.

A example on Grails with Vaadin here https://bitbucket.org/aluismarte/testlazycontainervaadingrails

On Grails with Vaadin 7.4.3 has errors.

Sample code

public class DemoDomainContainer extends LazyPagedContainer<TableClass> {

	private static final long serialVersionUID = 3018567394091518443L;

	public DemoDomainContainer() {
		super(TableClass.class);
	}

}
import java.util.List;

import javax.servlet.annotation.WebServlet;

import com.alsnightsoft.vaadin.containers.LazyQuery;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.data.Property;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Theme("lazypagedcontainer")
public class LazypagedcontainerUI extends UI {

	private VerticalLayout mainLayout;

	private DemoDomainContainer container;
	private ServiceDemo service = new ServiceDemo();

	private TextField tfFilterName;
	private CheckBox chkEnable;
	private Table tableDemo;

	@WebServlet(value = "/*", asyncSupported = true)
	@VaadinServletConfiguration(productionMode = false, ui = LazypagedcontainerUI.class)
	public static class Servlet extends VaadinServlet {
	}

	@Override
	protected void init(VaadinRequest request) {
		mainLayout = new VerticalLayout();

		container = new DemoDomainContainer();

		tfFilterName = new TextField("Filter");
		tfFilterName.setImmediate(true);
		tfFilterName.addValueChangeListener(new Property.ValueChangeListener() {
			@Override
			public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
				if (tfFilterName.getValue().equals("")) {
					container.setApplyLazyFilter(false);
				} else {
					container.setApplyLazyFilter(true);
				}
				tableDemo.refreshRowCache();
				tableDemo.markAsDirty();
			}
		});

		chkEnable = new CheckBox("Show Disable");
		chkEnable.setImmediate(true);
		chkEnable.setValue(false);
		chkEnable.addValueChangeListener(new Property.ValueChangeListener() {
			@Override
			public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
				tableDemo.refreshRowCache();
				tableDemo.markAsDirty();
			}
		});

		container.setLazyQuery(new LazyQuery<DemoDomain>() {
			@Override
			public int getLazySize() {
				return service.count();
			}

			@Override
			public List<DemoDomain> getLazyItemsIds(int startIndex,
					int numberOfIds) {
				return service.getItemsFromTo(startIndex, numberOfIds);
			}

			@Override
			public int getLazyFilteredSize() {
				return service.countFilter(tfFilterName.getValue());
			}

			@Override
			public List<DemoDomain> getLazyFilteredItemsIds(int startIndex,
					int numberOfIds) {
				return service.getFilterItemsFromTo(tfFilterName.getValue(),
						startIndex, numberOfIds);
			}
		});
		// disable use filter query (default false)
		container.setApplyLazyFilter(false);

		tableDemo = new Table();
		tableDemo.setSelectable(true);
		tableDemo.setImmediate(true);
		// tableDemo.setPageLength(5);
		tableDemo.setSizeFull();
		tableDemo.setFooterVisible(true);
		tableDemo.setColumnReorderingAllowed(false);
		tableDemo.setColumnCollapsingAllowed(true);
		tableDemo.setContainerDataSource(container);
		tableDemo.setVisibleColumns(new Object[] { "id", "name" });
		tableDemo.setColumnHeader("id", "ID");
		tableDemo.setColumnHeader("name", "Name");
		tableDemo.addValueChangeListener(new Property.ValueChangeListener() {
			@Override
			public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
				System.out.println("Change Value");
			}
		});

		mainLayout.addComponent(tfFilterName);
		mainLayout.addComponent(chkEnable);
		mainLayout.addComponent(tableDemo);

		// When add or update data on DB use that to refresh Table
		// Can use filter on the table if do it when add news values to the db.
		// Only filter items on the view, other items need a filter query on the
		// LazyQuery
		tableDemo.refreshRowCache();

		setContent(mainLayout);
	}

}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Fix to work with grid.

Released
2015-04-09
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.3+
Browser
Browser Independent

Lazy Paged Container - Vaadin Add-on Directory

A lazy paged container for minimal bandwidth Lazy Paged Container - Vaadin Add-on Directory
Perfect is you want implement yours on filters but on your server. A complete example on the source code. A example on Grails with Vaadin here https://bitbucket.org/aluismarte/testlazycontainervaadingrails On Grails with Vaadin 7.4.3 has errors.
Online