Skip to content

Instantly share code, notes, and snippets.

public class FileBean {
private UploadedFile file;
public void setUploadedFile(UploadedFile file) {
this.file = file;
}
public UploadedFile getUploadedFile() {
return file;
}
@uklance
uklance / MyPage.java
Last active August 29, 2015 14:06
Dynamic template usage
public class MyPage {
@Inject
private DynamicTemplateParser parser;
public DynamicTemplate getMyDynamicTemplate() {
// if you want this to come from a string you might need to
// implement a StringResource by extending AbstractResource
Resource resource = new ClasspathResource("path/to/some-template.tml");
return parser.parseTemplate(resource);
}
@uklance
uklance / BlockContainer.java
Last active August 29, 2015 14:05
Tapestry5 Dialog Avoiding Nested Forms
public interface BlockContainer {
void addBlock(Block block);
}
@uklance
uklance / AppModule.java
Last active August 29, 2015 14:01
Tapestry: Custom BeanModel to support "is" getters for javal.ang.Boolean
public class AppModule {
public static BeanModelSource decorateBeanModelSource(BeanModelSource defaultImpl) {
return new MyBeanModelSource(defaultImpl);
}
}
@uklance
uklance / RunNotifierJUnit4ClassRunner.java
Created April 2, 2014 07:51
BlockJUnit4ClassRunner events
package sandbox.junit;
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
import org.junit.runner.notification.StoppedByUserException;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
public class ConverterGridDataSource implements GridDataSource {
private final GridDataSource delegate;
private final Converter converter;
public ConverterGridDataSource(GridDataSource delegate, Converter converter) {
this.delegate = delegate;
this.converter = converter;
}
public int getAvailableRows() {
207.61.224.54 - - [06/Jan/2014:05:44:15 +0000] "GET / HTTP/1.1" 200 606 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/6.1.1 Safari/537.73.11"
207.61.224.54 - - [06/Jan/2014:05:44:16 +0000] "GET /assets/1.0-SNAPSHOT/tapestry/default.css HTTP/1.1" 200 2089 "http://tapestry-atmosphere.uklance.cloudbees.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/6.1.1 Safari/537.73.11"
207.61.224.54 - - [06/Jan/2014:05:44:16 +0000] "GET /assets/1.0-SNAPSHOT/ctx/bootstrap/css/bootstrap.css HTTP/1.1" 200 17911 "http://tapestry-atmosphere.uklance.cloudbees.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/6.1.1 Safari/537.73.11"
207.61.224.54 - - [06/Jan/2014:05:44:34 +0000] "GET /chatdemo;jsessionid=a5g6txxdf2uo10detrcbjztn HTTP/1.1" 200 3000 "http://tapestry-atmosphere.uklance.cloudbees.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.73.11 (
<!-- page.tml -->
<t:grid source="myCustomGridDataSource" ... />
// Page.java
public GridDataSource getMyCustomGridDataSource() {
final List<Document> docs = documentDAO.getAll();
GridDataSource wrapper = new CollectionGridDataSource(docs) {
public int getAvailableRows() {
return super.getAvailableRows() + 1;
}
@Property
private Country country;
@Property
private City city;
public Country[] getCountries() {
return new Country[] { ... };
}
@uklance
uklance / LazyTreeModel.java
Last active December 18, 2015 14:18
A more database friendly TreeModel implementation
public class LazyTreeModel<T> implements TreeModel<T> {
private final ValueEncoder<T> encoder;
private final LazyTreeModelSource<T> source;
public LazyTreeModel<T>(ValueEncoder<T> encoder, LazyTreeModelSource<T> source) {
this.encoder = encoder;
this.source = source;
}
@Override