最近在看Vaadin 需要用Vaadin 做一个二维码 选用了Zing 谷歌的生成包;
参考下面的VaadinAPI
// Create the stream resource with some initial filename
StreamResource imageResource =
new StreamResource(imageSource, "initial-filename.png");
// Instruct browser not to cache the image
imageResource.setCacheTime(0);
// Display the image
Image image = new Image(null, imageResource);
刷新时, 你还需要对 Image 对象调用 markAsDirty() 方法.
// This needs to be done, but is not sufficient
image.markAsDirty();
// Generate a filename with a timestamp
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String filename = "myfilename-" + df.format(new Date()) + ".png";
// Replace the filename in the resource
imageResource.setFilename(makeImageFilename());
然而上面代码并未用什么用 参考api后修改为
String token=new Md5PasswordEncoder().encodePassword(new Date().toString(),username+password);
identityService.setUserToken(username,token);
StreamResource.StreamSource imagesource = new MyImageSource(token);
StreamResource resource = new StreamResource(imagesource, "myimage.png", ExplorerApp.get());
Embedded image = new Embedded(null, resource);
image.setHeight("100%");
image.setWidth("100%");
form_image.getLayout().removeAllComponents();
form_image.getLayout().addComponent(image);
这文档还是挺坑人的 在StreamResource方法时必须有application参数
然后就是image组件 大家可以试试 vaadin中并没有直接用的image组件