你好我是stackoverflow中的新手我正在使用primefaces 3.5我的问题是,是否有必要在静态块或构造函数中设置selectonemenu项目(java util的Map)。 像:
slider.xhtml
<h:outputLink value="circle">
<h:outputText value="click Circle!"/>
</h:outputLink>
漂亮-config.xml中
<url-mapping id="circle">
<pattern value="/circle" />
<view-id value="xhtmls/circle.xhtml" />
<action>#{circleAction.action}</action>
</url-mapping>
CircleAction.java
public class CircleAction {
private String favCoffee2;
private Map<String,Object> coffee2Value;
//setter n getter
public Map<String,Object> getFavCoffee2Value() {
return coffee2Value;
}
public String action(){
coffee2Value = new LinkedHashMap<String,Object>();
coffee2Value.put("mohsin - Cream Latte", "Cream Latte"); //label, value
coffee2Value.put("mohsin - Extreme Mocha", "Extreme Mocha");
coffee2Value.put("mogsin - Buena Vista", "Buena Vista");
return "pretty:addcircle";
}
}
circle.xhtml
<p:selectOneMenu value="#{circleAction.favCoffee2}">
<f:selectItems value="#{circleAction.favCoffee2Value}" />
</p:selectOneMenu>
selectOneMenu在这种情况下是空白但是当我从动作方法中删除下面的代码并将其放在静态块中时,selectOneMenu将生成java.util.map中的所有项目;
coffee2Value = new LinkedHashMap<String,Object>();
coffee2Value.put("mohsin - Cream Latte", "Cream Latte"); //label, value
coffee2Value.put("mohsin - Extreme Mocha", "Extreme Mocha");
coffee2Value.put("mogsin - Buena Vista", "Buena Vista");
答案 0 :(得分:0)
问题在于,当您访问/circle
时,PrettyFaces会执行您的操作方法,并在您返回pretty:addcircle
时将您重定向到新页面。因此,请求范围bean(尤其是映射)的所有值都将丢失。只需从方法返回null
即可。在这种情况下,PrettyFaces将只渲染xhtmls/circle.xhtml
,这可能是你想要的。