简体   繁体   English

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

[英]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. HTML输入元素的值通常作为HTTP请求参数提交,而输入字段名称作为请求参数名称。 So if you know the JSF-generated HTML input field name, then you'll be able to grab it from the request parameter map. 因此,如果您知道JSF生成的HTML输入字段名称,则可以从请求参数映射中获取它。

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. 通常,通常通过UIInput组件的value属性将输入值直接绑定到支持Bean属性,这样JSF将完成收集请求参数,转换/验证它们以及更新模型值的所有工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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