所选元素未设置为辅助bean

时间:2013-05-13 01:59:14

标签: jsf

我的jsp中有以下字段。选定的值未设置为元素。 当我在FF中的这个下拉字段中执行Inspect元素时,它显示未选择元素。它也没有设置为支持bean。 我错过了什么?

    <h:selectOnMenu id="scriptEngine"  value="#{AddScriptBean.scriptEngine}" required="true">
        <f:selectItems value="#{AddScriptBean.scriptEngines}"/>
    </h:selectOneMenu> 

支持bean代码如下

    public List<SelectItem> getScriptEngines() {
    List<SelectItem> items = new ArrayList<SelectItem>();
    try { 
        GetScriptEngineNamesCommand command = (GetScriptEngineNamesCommand) CommandFactory.getInstance().getCommand(GetScriptEngineNamesCommand.class.getName());
        command.doExecute();
        Map<String, String> engineNames = command.getEngineNames();
        MessageSource messageSource = getMessageSource();
        Locale  locale = RequestUtils.getUserLocale((HttpServletRequest) FacesContext.getCurrentInstance()
                    .getExternalContext().getRequest(), Globals.LOCALE_KEY); 
        String label = messageSource.getFormattedMessage(locale, "com.soa.console.faces.script.select", new Object[] {});
        items.add(new SelectItem("", label));
        for (String name : engineNames.keySet()){
            items.add(new SelectItem(engineNames.get(name), name));
        }

    }catch (GException e){
        String eMessage = e.toString();
        FacesMessage msg = new FacesMessage("", eMessage);
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    return items;
}

1 个答案:

答案 0 :(得分:0)

我认为getter方法不会调用因为你已经使用 scriptEngines <f:selectItems>标记绑定到bean,但是你的getter方法是 getScriptEngines()。它应该已经被getscriptEngines()。这可能是问题