使用JSF 2.2(Primefaces 5.0)动态创建链接的图像的

问题描述 投票:-1回答:1

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>

jsf jsf-2 primefaces
1个回答
0
投票

像这样的作品..

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。

© www.soinside.com 2019 - 2024. All rights reserved.