使用 JSF 获取 HTML 值
我有一个 javascript 可以编辑 jsf 页面中的隐藏字段:
<h:inputHidden id="data" value="" />
当我单击“提交”时,我想获取由 javascript 修改的该 HTML 字段的新值。我已经研究过
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("data");
但这似乎只有在作为
传入时才有效。有没有办法可以通过 bean 调用获取值?
I have a javascript that edits a hidden field in my jsf page:
<h:inputHidden id="data" value="" />
and when I click on "Submit" I would like to get the new value of this HTML field that was modified by the javascript. I've looked into
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("data");
But that seems only to work if it is passed in as an <f:param/>
. Is there a way i can get the value through a bean call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是生成的 HTML 输入字段的名称,该字段以通常的 HTTP/HTML 方式作为请求参数发送。请记住:JSF 在 Web 服务器上运行,生成 HTML/CSS/JS,Web 服务器通过 HTTP 将其发送到 Web 浏览器,Web 浏览器检索 HTML/CSS/JS 并显示/应用/执行它。在浏览器中右键单击页面,选择查看源代码,找到生成的 HTML 输入元素,您将看到类似以下内容:
其中
formid
是父级的 ID< ;form>
由 JSF
生成。根据 HTML 规范,输入值以请求参数中的名称=值对的形式发送。因此,对于上述情况,您应该使用
但是,您也可以将其绑定到 bean 属性。
这样,它就可以在 bean 的操作方法中作为
data
属性使用,而无需以低级方式处理请求参数。It's the name of the generated HTML input field which get sent as request parameter the usual HTTP/HTML way. Remember: JSF runs at webserver, produces HTML/CSS/JS, webserver sends it by HTTP to webbrowser, webbrowser retrieves HTML/CSS/JS and displays/applies/executes it. Rightclick page in browser, choose View Source, locate the generated HTML input element and you'll see something similar this:
where
formid
is the ID of the parent<form>
as generated by JSF<h:form>
. As per the HTML spec, input values get sent as name=value pairs in request parameters.So, for the above case, you should be using
However, you can also just bind it to a bean property.
This way it'll just be available as
data
property in the bean's action method without the need to hassle with request parameters the low-level way.