public void handleAction(JbpmJsfContext context, ActionEvent event) {
try {
final FacesContext facesContext = FacesContext.getCurrentInstance();
final ELContext elContext = facesContext.getELContext();
final IdentitySession identitySession = new IdentitySession(context.getJbpmContext().getSession());
if (userNameExpression == null) {
context.setError("Error creating user", "The user name expression is missing");
return;
}
final Object userNameValue = userNameExpression.getValue(elContext);
if (userNameValue == null) {
context.setError("Error creating user", "The user name value is null");
return;
}
final User user = new User(userNameValue.toString());
if (passwordExpression != null) {
final Object passwordValue = passwordExpression.getValue(elContext);
if (passwordValue == null) {
context.setError("Error creating user", "The password value is null");
return;
}
if (passwordConfirmExpression != null) {
final Object passwordConfirmValue = passwordConfirmExpression.getValue(elContext);
if (! passwordValue.equals(passwordConfirmValue)) {
context.setError("Error creating user", "The password confirmation value does not match the password value");
return;
}
}
user.setPassword(passwordValue.toString());
}
if (emailExpression != null) {
final Object emailValue = emailExpression.getValue(elContext);
if (emailValue == null) {
context.setError("Error creating user", "The email value is null");
return;
}
user.setEmail(emailValue.toString());
}
identitySession.saveUser(user);
if (targetExpression != null) {
targetExpression.setValue(elContext, user);
}
context.selectOutcome("success");
context.addSuccessMessage("User created successfully");