JSF 2.2,5.0 Primefaces,
我要的只是它链接到网站的图片。这应该使用Java产生。
JSF:
<ui:component binding="#{bean.content}" />
豆角,扁豆:
public UIComponent getContent() {
GraphicImage image = (GraphicImage) FacesContext.getCurrentInstance().getApplication().createComponent(GraphicImage.COMPONENT_TYPE);
image.setValue(imagePath);
Link link = (Link) FacesContext.getCurrentInstance().getApplication().createComponent(Link.COMPONENT_TYPE);
link.setHref(uri);
...
}
我怎样才能把一个图像到链接标签?
我试过link.setValue(image)
。它没有工作。刚刚得到的图像对象的toString表示。
结果HTML应该是这样的:
<a href="www.uri.com"><img src="image.jpg"></a>
像这样的作品..
public UIComponent getContent() {
GraphicImage image = (GraphicImage) FacesContext.getCurrentInstance().getApplication().createComponent(GraphicImage.COMPONENT_TYPE);
image.setUrl("yourimage.jpg");
image.setOnclick("window.open('http://stackoverflow.com');");
return image;
}
更改路径和相应的URL。