检索不具有托管bean属性的JSF输入字段的值 [英] Retrieving value of JSF input field without managed bean property

查看:123
本文介绍了检索不具有托管bean属性的JSF输入字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在托管bean动作方法中检索JSF输入框的值,而不将其与任何托管bean属性关联.例如

I would like to retrieve the value of JSF input box in a managed bean action method, without it being associated with any managed bean property. E.g.

<p:inputText id="txtuserid" value="" />

我的用例是在我的应用程序中,我想在这里和那里提示用户输入每个DML操作的密码,因此希望在每个UI上都有一个密码和与注释相关的字段,并且注释必须是保存在公用表中以供审核.

My use case is that in my application I will like to prompt user here and there for passwords for every DML operations, and therefore like to have a password and comment related fields on each of my UI, and the remarks needs to be saved in a common table for audit purpose.

我该如何实现?

推荐答案

与JSF在幕后所做的相同:获取HTTP请求参数.如果您熟悉基本的HTML,那么您就会知道每个HTML输入元素都会将其name=value对作为HTTP请求参数发送.

Just do the same as JSF is doing under the covers: grabbing the HTTP request parameter. If you're familiar with basic HTML, you know that every HTML input element sends its name=value pair as HTTP request parameter.

给出一个

<h:form id="formId">
    <p:inputText id="userId" /> <!-- Note: no value attribute at all, also no empty string! -->
    ...
    <p:commandButton value="submit" action="#{bean.submit}" />
</h:form>

基本上会生成 以下HTML

which generates basically the following HTML

<form id="formId" name="formId">
    <input type="text" name="formId:userId" ... />
    ...
    <button type="submit" ...>submit</button>
</form>

您可以从

别忘了在必要时手动转换和验证它,就像JSF在幕后所做的那样.换句话说,只需编写其他代码来重复JSF的工作,这样您的代码就不会 DRY :)

Don't forget to manually convert and validate it if necessary, like as JSF is doing under the covers. In other words, just repeat the JSF's job by writing additional code so that your code is not DRY :)

这篇关于检索不具有托管bean属性的JSF输入字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆