Reputation: 871
I have a simple "register" page built with primefaces tags where user inputs his login, clicks OK and that info is stored in DB via POST request to a bean. Login is saved properly, but there is another one... I want to store implicit String field which represents user's "role" and is always equal to "Guest". I've tried two different approaches but all of them failed for me:
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>
could anybody provide an idea for me? thx. environment: jdk7, tomcat7, eclipse, primefaces
Upvotes: 0
Views: 2042
Reputation: 1109865
Use either plain HTML <input type="hidden">
or JSF <f:param>
along with a @ManagedProperty
.
So, either
<input type="hidden" name="rolename" value="Guest" />
or
<p:commandButton ...>
<f:param name="rolename" value="Guest" />
</p:commandButton>
Either way, they're available as a HTTP request parameter by
@ManagedProperty("#{param.rolename}")
private String rolename; // +getter+setter
Upvotes: 2