使用 JSF 获取 HTML 值

发布于 2024-10-10 05:38:34 字数 368 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み零 2024-10-17 05:38:35

它是生成的 HTML 输入字段的名称,该字段以通常的 HTTP/HTML 方式作为请求参数发送。请记住:JSF 在 Web 服务器上运行,生成 HTML/CSS/JS,Web 服务器通过 HTTP 将其发送到 Web 浏览器,Web 浏览器检索 HTML/CSS/JS 并显示/应用/执行它。在浏览器中右键单击页面,选择查看源代码,找到生成的 HTML 输入元素,您将看到类似以下内容:

<input type="hidden" id="formid:data" name="formid:data" />

其中 formid 是父级的 ID < ;form> 由 JSF 生成。根据 HTML 规范,输入值以请求参数中的名称=值对的形式发送。

因此,对于上述情况,您应该使用

data = requestParameterMap.get("formid:data");

但是,您也可以将其绑定到 bean 属性。

<h:inputHidden value="#{bean.data}" />

这样,它就可以在 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:

<input type="hidden" id="formid:data" name="formid:data" />

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

data = requestParameterMap.get("formid:data");

However, you can also just bind it to a bean property.

<h:inputHidden value="#{bean.data}" />

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文