通过这个code,我能够返回基于关闭的下拉列表选择一个图像。如何返回多个图像的任何想法(我试图创建与图像的ArrayList和使用UI:重复标记,以使其回到我的看法,但我没有成功这是我目前的code现在,这工作,但只有在什么办法才能让多个图像返回一个图像。任何想法?
的Java code:
(Person类有属性:私人字符串theImage;)
公共字符串getTheImage(){
如果(this.theSchoolChoice.equals(阿拉巴马大学)){
theImage =/resources/gfx/UofALogo.png;
}
如果(this.theSchoolChoice.equals(哈佛大学)){
}
返回theImage;
}
JSF code:
< H:selectOneMenu用于值=#{person.theSchoolChoice}的风格=宽度:179px;高度:21px;>
< F:selectItems的值=#{person.theOptions}/>
< / H:selectOneMenu用于>
< H:outputLabel值=/>
< H:的commandButton行动=提交值=获取模板的风格=FONT-SIZE:中等; FONT-FAMILY:'洛';宽度:128像素,高度:25像素;>
< F:Ajax事件=变渲染=形象/>
< / H:的commandButton>
< BR>< / BR>
< BR>< / BR>
< H:graphicImage的ID =形象的价值=#{person.theImage}/>
解决方案
至于说在你的第一个问题有关这个问题,我建议弄个所有图像在地图<字符串列表与LT;字符串>>
其中地图关键是下拉值与映射值是图像集合
既然你似乎无法弄明白,这里有一个开球例如JSF页面应该是什么样子:
< H:形式GT;
< H:selectOneMenu用于值=#{bean.groupName}>
< F:选择信息itemValue =请选择一个/>
< F:selectItems的值=#{bean.groupNames}/>
< F:Ajax事件=变渲染=图像/>
< / H:selectOneMenu用于>
< H:panelGroup中的id =图片>
< UI:重复值=#{bean.images}VAR =形象>
< H:graphicImage的价值=#{}形象/>
< / UI:重复>
< /小时:panelGroup中>
< /小时:形式GT;
和这里是如何关联的豆
应该是这样的:
@ManagedBean
@ViewScoped
公共类豆{
私人地图<字符串列表与LT;字符串>> allImages =新的LinkedHashMap<字符串列表与LT;字符串>>();
私人列表<字符串>组名;
私人字符串组名;
公共豆(){
allImages.put(组1,Arrays.asList(group1a.jpg,group1b.jpg,group1c.jpg));
allImages.put(组2,Arrays.asList(group2a.jpg,group2b.jpg,group2c.jpg));
allImages.put(组3,Arrays.asList(group3a.jpg,group3b.jpg,group3c.jpg));
组名=新的ArrayList<字符串>(allImages.keySet());
}
公开名单<字符串> getImages(){
返回allImages.get(组名);
}
公开名单<字符串> getGroupNames(){
返回组名;
}
公共字符串getGroupName(){
返回组名;
}
公共无效setGroupName(字符串组名){
this.groupName =组名;
}
}
With this code, I am able to return one image based off of a dropdown selection. Any ideas on how to return multiple images (I have attempted to create an ArrayList with the images and use the UI:Repeat tag to render it back to my view, but I was unsuccessful. Here is my current code now, which works but only returns one image. Any ideas on what approach to take to get more than one image?
Java Code:
(Person class has attribute: private String theImage;)
public String getTheImage(){
if(this.theSchoolChoice.equals("University of Alabama")){
theImage = "/resources/gfx/UofALogo.png";
}
if(this.theSchoolChoice.equals("Harvard University")){
}
return theImage;
}
JSF Code:
<h:selectOneMenu value="#{person.theSchoolChoice}" style="width : 179px; height : 21px;">
<f:selectItems value="#{person.theOptions}"/>
</h:selectOneMenu>
<h:outputLabel value=" "/>
<h:commandButton action="submit" value="Get templates" style="FONT-SIZE: medium; FONT-FAMILY: 'Rockwell';width : 128px; height : 25px;">
<f:ajax event="change" render="image" />
</h:commandButton>
<br></br>
<br></br>
<h:graphicImage id="image" value="#{person.theImage}"/>
解决方案
As told in your first question about the subject, I have suggested to get hold of all images in a Map<String, List<String>>
where the map key is the dropdown value and the map value is the collection of images.
Since you can't seem to figure it out, here's a kickoff example how the JSF page should look like:
<h:form>
<h:selectOneMenu value="#{bean.groupName}">
<f:selectItem itemValue="Please select one" />
<f:selectItems value="#{bean.groupNames}" />
<f:ajax event="change" render="images" />
</h:selectOneMenu>
<h:panelGroup id="images">
<ui:repeat value="#{bean.images}" var="image">
<h:graphicImage value="#{image}" />
</ui:repeat>
</h:panelGroup>
</h:form>
And here's how the associated Bean
should look like:
@ManagedBean
@ViewScoped
public class Bean {
private Map<String, List<String>> allImages = new LinkedHashMap<String, List<String>>();
private List<String> groupNames;
private String groupName;
public Bean() {
allImages.put("group1", Arrays.asList("group1a.jpg", "group1b.jpg", "group1c.jpg"));
allImages.put("group2", Arrays.asList("group2a.jpg", "group2b.jpg", "group2c.jpg"));
allImages.put("group3", Arrays.asList("group3a.jpg", "group3b.jpg", "group3c.jpg"));
groupNames = new ArrayList<String>(allImages.keySet());
}
public List<String> getImages() {
return allImages.get(groupName);
}
public List<String> getGroupNames() {
return groupNames;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
}