我有一个使用 primefaces 标签构建的简单“注册”页面,用户在其中输入他的登录名,单击“确定”,该信息通过对 bean 的 POST 请求存储在数据库中。登录已正确保存,但还有另一个...... 我想存储代表用户“角色”且始终等于“Guest”的隐式字符串字段。我尝试了两种不同的方法,但对我来说都失败了:
1)
<h:outputLabel for="login" value="Login" />
<p:inputText required="true" id="login" value="#{userBean.login}"
label="Login" />
<h:inputHidden value="#{userBean.roleName}" id="rolename"
name="Guest" />
<p:commandButton value="OK" update="dataForm" action="#{userBean.create}"
ajax="false">
2)
<h:outputLabel for="login" value="Login" />
<p:inputText required="true" id="login" value="#{userBean.login}"
label="Login" />
<p:commandButton value="OK" update="dataForm" action="#{userBean.create}"
ajax="false">
<f:param id="rolename" value="User" binding="#{userBean.roleName}"/>
</p:commandButton>
有人可以给我出主意吗? 谢谢。 环境:jdk7、tomcat7、eclipse、primefaces
最佳答案
使用纯 HTML <input type="hidden">
或 JSF <f:param>
连同 @ManagedProperty
.
所以,要么
<input type="hidden" name="rolename" value="Guest" />
或
<p:commandButton ...>
<f:param name="rolename" value="Guest" />
</p:commandButton>
无论哪种方式,它们都可以通过
作为 HTTP 请求参数使用@ManagedProperty("#{param.rolename}")
private String rolename; // +getter+setter
关于jsf - 如何将字符串值从 <h :inputHidden> to a bean property?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17544976/