tapestryでimageを表示するサンプルプログラム
javaコード下記:
public class ImageTest {
@Inject
private ComponentResources _resources;
public Link getChart3() {
return _resources.createEventLink(“chart", false, null);
}
public StreamResponse onChart(){
return new StreamResponse() {
public String getContentType(){
return “image/png";
}
public InputStream getStream() throws IOException {
try {
return new ClasspathResource(“diagrams/vacation.png").openStream();
} catch (IOException ex) {
throw new RuntimeException(“Cannot read image file.", ex);
}
}
public void prepareResponse(Response response){}
};
}
}
ImageTest.tmlファイル
<html
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter">
<header>
<title>show image</title>
</header>
<body>
<img src="${chart3}"/>
</body>
</html>