0

I have following field in my jsp. Selected value is not set to the element. When I did Inspect element on this drop down field in FF, it shows that element is not selected. Also its not set to the backing bean. What am I missing?

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

The backing bean code is as follows

    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;
}
Parag A
  • 443
  • 2
  • 8
  • 20
  • The editor offers a button for "code sample". Or just begin the line with 4 spaces. That way the editor will not try to sanitize your text. – SJuan76 May 13 '13 at 02:03
  • Share the code of the backing bean too... – Himanshu Bhardwaj May 13 '13 at 03:54
  • Beannames start with a lowercase letter. Also consider to keep the GETer methods from all beans slim. Try to do all the processing in some initialize method, annotated with `@PostConstruct`. – Manuel May 13 '13 at 04:41
  • I am not following. Did you mean I shud do the job of adding the items in the Constructor or something? – Parag A May 13 '13 at 05:04
  • You need getter setters. http://stackoverflow.com/a/2036991/892994 and also read this tutorial for better understanding http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html – erencan May 13 '13 at 06:26

1 Answers1

0

I guess getter method is not calling becuase you have bounded <f:selectItems> tag to the bean with scriptEngines but your getter method is getScriptEngines().It should have been getscriptEngines().This could be the problem

Archana
  • 3,213
  • 1
  • 15
  • 21
  • May be you have some validation or conversion errors so bean values are not updating.You can use to show any messages – Archana May 14 '13 at 04:31
  • For a variable named as `scriptEngines`, the getter method will be `getScriptEngines()` only, hence there is no problem with the getter function name. – Logan May 14 '13 at 10:51
  • Some IDE will generate it as getscriptEngines().So i thought that would be the problem. – Archana May 14 '13 at 10:58