2013-03-19 54 views
0

你好我是新來的在這裏在stackoverflow我使用的是primefaces 3.5我的問題是,是否有必要在靜態塊或構造函數中設置selectonemenu項目(Java util的Map).. like:無法在primefaces中生成selectonemenu項目

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中的所有項目。地圖;

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

的問題是,當你訪問/circle,PrettyFaces將執行你的操作方法,併爲您返回pretty:addcircle您重定向到一個新的一頁。因此,請求範圍的bean(特別是地圖)的所有值都將丟失。只需返回null從該方法應該工作。在這種情況下,PrettyFaces只會渲染xhtmls/circle.xhtml,這可能是你想要的。

+0

那我該怎麼辦?我 2013-03-20 15:23:56

+0

那我該怎麼辦?我有其中我想調用處理一些數據並將其呈現給SELECTONEMENU的'ACTION'方法,因爲之前我做過一個表單,我選擇了一些值並提交' {circleAction.edit}該值爲同一類(CIRCLE ACTION)但編輯()方法,但它不工作,因爲當我點擊我的瀏覽器URL是http:// localhost/myApp /調用URL後調用#{circleAction.ation}的循環是http:// localhost/myApp/addcircle,但是selectOneMenu不是wrking, – 2013-03-20 15:35:48

+0

如果我使用URL localhost/myApp/circle,它總是調用操作方法,但我也想調用編輯方法 – 2013-03-20 15:37:28

相關問題