2015-07-28 40 views
0

我使用的選擇一個菜單從map<String,Integer>選擇,但它只是選擇0JSF選擇一個菜單設置錯誤

<p:fieldset id="locations" legend="locations" toggleable="false"> 
     <p:selectOneMenu id="locations" value="#{bean.selectedLocation}" filter="true" filterMatchMode="contains"> 
      <f:selectItems value="#{bean.availableLocations}"/> 
     </p:selectOneMenu> 
    </p:fieldset> 

和我的豆是:

@ManagedBean 
@ViewScoped 
public class Bean { 
private Map<String, Integer> availableLocations = new HashMap<>(); 
private int     selectedLocation = 1; 


public int getSelectedLocation() { 
    return selectedLocation; 
} 
public void setSelectedLocation(int selectedLocation) { 
    this.selectedLocation=selectedLocation; 
} 

@Override 
protected void init() { 
     availableLocations.clear(); 
     availableLocations.putAll(Locations.getLocations()); 
} 

}

當我選擇任何項目,它只是設置0selectedLocation

當我把我的字段集到它從來沒有任何提前

感謝的形式,

+0

要排除一個和其他,如果你設置菜單組件上的'converter =「javax.faces.Integer」'? – BalusC

+0

謝謝@BalusC,不,它不工作 –

回答

0

我通過添加ajax發現問題

,問題就會解決

​​3210
+0

哦?所以你的主表單提交按鈕根本不處理菜單值?你是否在提交按鈕中使用'process =「@ this」'?如果是這樣,那麼你的回答只是一種解決方法,而不是一個真正的解決方案。 – BalusC

+0

不,這個表單只有一個選擇菜單來選擇bean上的一個變量,這個表單還包含另外一個字段集,當這個字段集被渲染時,這個字段集不會渲染 –

+0

你有更大的問題。無論如何,在將來的問題中,請記住發佈一個真正的MCVE。在目前的形式下,這一切都不存在。你可能不可能收到你真正需要的答案,而這個答案在實際的代碼中沒有洞察力。另見http://stackoverflow.com/tags/jsf/info。 – BalusC