0

Is is possible to access the value that is in a selectOneMenu through FacesContext?

Catfish
  • 18,876
  • 54
  • 209
  • 353

1 Answers1

3

The values of HTML input elements are normally submitted as HTTP request parameters with the input field name as request parameter name. So if you know the JSF-generated HTML input field name, then you'll be able to grab it from the request parameter map.

E.g.

<h:form id="formId">
    <h:selectOneMenu id="menuId">
        ...

and

String menuValue = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("formId:menuId");
// ...

The usefulness of this is however highly questionable. You normally bind input values to backing bean properties directly by the value attribute of UIInput components so that JSF will do all the job of gathering request parameters, converting/validating them and updating the model values.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks alot it worked great. I know it's not the best way to do that and the only reason i'm doing it this way is to solve this problem - http://stackoverflow.com/questions/10520204/jsf-issue-with-back-button/10520820#comment13611876_10520820. This helped me tremendously. Thanks. – Catfish May 10 '12 at 17:58