【问题标题】:JSF select one menu set wrongJSF选择一个菜单设置错误
【发布时间】:2015-07-28 10:16:15
【问题描述】:

我正在使用选择一个菜单从map<String,Integer> 中进行选择,但它只选择0

 <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());
}

}

当我选择任何项目时,它只是将0 设置为selectedLocation

当我将我的字段集放入表单时,它从未设置任何内容

提前致谢,

【问题讨论】:

  • 要排除一个和另一个,如果在菜单组件上设置converter="javax.faces.Integer"会怎样?
  • 谢谢@BalusC,不,它不起作用

标签: jsf jsf-2 primefaces hashmap selectonemenu


【解决方案1】:

我发现了问题

通过添加ajax,问题将得到解决

<p:ajax event="change" update="@this" />

【讨论】:

  • 哦?所以你的主表单提交按钮根本没有处理菜单值?您是否在提交按钮中使用process="@this"?如果是这样,那么您的答案只是一种解决方法,而不是真正的解决方案。
  • 不,这个表单只有一个选择一个菜单来选择bean上的一个变量,这个表单还包含另一个字段集,当这个字段集呈现时不会呈现
  • 你有一个更大的问题。无论如何,在以后的问题中,请记住发布一个真实的 MCVE。在当前形式的问题中,这一切都看不到。你不可能从不了解实际代码的人那里得到你真正需要的答案。另请参阅stackoverflow.com/tags/jsf/info
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-30
相关资源
最近更新 更多