返回JSF页面上的图像列表 [英] Returning list of images on JSF page
问题描述
我有一个用户可以从中选择的项的下拉列表(视图是JSF).我希望在用户从下拉列表中选择一个项目后,图像会出现在同一JSF页面上(即,用户从下拉列表中选择单词猫",然后出现一组不同的猫图像)
I have a dropdown list of items a user can select from (the view is JSF). I would like for an image to appear on the same JSF page after a user selects an item from the dropdown list (i.e. A user select the word "Cat" from the dropdown list, and group of different cat images appear)
我该如何在JSF中编写代码?
How would I code this in JSF?
注意*我正在将JSF 2.0与facelets一起使用,而不是JSP.
Note* I'm using JSF 2.0 with facelets, not JSPs.
推荐答案
在下拉列表中提供带有图像URL的列表,并使用h:graphicImage
在所选URL上显示图像.然后,使用f:ajax
在更改下拉菜单时重新渲染图像.
Provide a list with image URL's in the dropdown and use h:graphicImage
to display an image on the selected URL. Then, use f:ajax
to re-render the image on change the dropdown.
这是一个开球示例:
<h:form>
<h:selectOneMenu value="#{bean.imageURL}">
<f:selectItems value="#{bean.imageURLs}" />
<f:ajax event="change" render="image" />
</h:selectOneMenu>
<h:graphicImage id="image" value="#{bean.imageURL}" />
</h:form>
Bean:
private List<String> imageURLs; // +getter
private String imageURL; // +getter +setter
这篇关于返回JSF页面上的图像列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!