Skip to content

Instantly share code, notes, and snippets.

@uklance
Created November 9, 2012 16:25
Show Gist options
  • Save uklance/4046654 to your computer and use it in GitHub Desktop.
Save uklance/4046654 to your computer and use it in GitHub Desktop.
package org.lazan.t5components.model;
import java.util.List;
public interface GalleryDataModel<T> {
int size();
List<T> getItems(int startIndex, int maxItems);
}
package org.lazan.t5components.demo.pages;
import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry5.Asset;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.AssetSource;
import org.lazan.t5components.model.GalleryDataModel;
public class GalleryDemo {
@Inject
private AssetSource assetSource;
@Property
private Asset image;
public GalleryDataModel<Asset> getImages() {
return new GalleryDataModel<Asset>() {
public int size() {
return 15;
}
public List<Asset> getItems(int startIndex, int maxItems) {
List<Asset> assets = new ArrayList<Asset>();
int itemCount = Math.min(size() - startIndex, maxItems);
for (int i = 0; i < itemCount; ++ i) {
String path = String.format("images/%s.jpg", i + startIndex);
assets.add(assetSource.getContextAsset(path, null));
}
return assets;
}
};
}
}
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xmlns:p="tapestry:parameter">
<t:lazan.gallery source="images" columnCount="literal:3" pageSize="literal:6" value="image">
<p:valueBlock>
<img src="${image}" />
</p:valueBlock>
</t:lazan.gallery>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment