你好,我是stackoverflow的新手我正在使用primefaces 3.5我的问题是,是否有必要在静态块或构造函数中设置selectonemenu项目(Java util的映射)..比如:
滑块.xhtml
<h:outputLink value="circle">
<h:outputText value="click Circle!"/>
</h:outputLink>
漂亮的配置.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";
}
}
圆圈.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");