简体   繁体   中英

JSF2 Can i access selectOneMenu value through FacesContext somehow?

是否可以通过FacesContext访问selectOneMenu中的值?

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.

Eg

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM