I have Java Web application, but I want to do the following:
When I log into my application with a certain user then I need to do some operations, such as saving some information in the database, but I want it at the time I do this insertion, I'll capture which user made this insertion , I want to get the user. How can I do this?
Button code that does the insert action:
<p:commandLink id="btn_save_users_modal"
action="#{messageBean.insert()}"
styleClass="btn btn-success"
update=":message_form"
validateClient="true">
<i class="fa fa-check fa-fw" /> #{bundle['system.ui.label.save']}
</p:commandLink>
Method below messageBean.insert()
inserts:
public void insert() {
try {
messageFacade.save(message);
} catch (Exception e) {
e.printStackTrace();
}
}
Here, for example, I want to insert this object of my message
and with the user that I just logged into my page.
I want to know which user made this insertion according to each user who logged into my page.
This is my login method (), when the page on the page makes some validations.
public String doLogin() {
// Força a JVM para pt-BR, assim a formatação numérica fica no formato
// brasileiro
Locale.setDefault(new Locale("pt", "BR"));
// Validações
if (this.username == null || this.username.equals("")) {
MessageGrowl.warn(
MessageProperties.getString("message.loginVazio"), false);
} else if (this.password == null || this.password.equals("")) {
MessageGrowl
.warn(MessageProperties.getString("message.passwordVazio"),
false);
} else {
// String hashedPassword = SecurityUtils.getHashedString(password);
this.loggedUser = loginUserFacade.getValideUser(username,password);
if (this.loggedUser != null) {
isAuthenticated = true;
redirectIfAlreadyLogged();
}
else {
MessageGrowl.error(MessageProperties
.getString("login.autenticacao"));
clear();
}
}
return "";
}