}
public static class SaveActionListener extends EventListener<UIAccountProfiles> {
public void execute(Event<UIAccountProfiles> event) throws Exception {
UIAccountProfiles uiForm = event.getSource();
OrganizationService service = uiForm.getApplicationComponent(OrganizationService.class);
WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
UIApplication uiApp = context.getUIApplication();
ConversationState state = ConversationState.getCurrent();
String userName = ((User) state.getAttribute(CacheUserProfileFilter.USER_PROFILE)).getUserName();
User user = service.getUserHandler().findUserByName(userName);
if (user != null) {
String oldEmail = user.getEmail();
String newEmail = uiForm.getUIStringInput("email").getValue();
// Check if mail address is already used
Query query = new Query();
query.setEmail(newEmail);
if (service.getUserHandler().findUsers(query).getAll().size() > 0 && !oldEmail.equals(newEmail)) {
// Be sure it keep old value
user.setEmail(oldEmail);
Object[] args = { userName };
uiApp.addMessage(new ApplicationMessage("UIAccountInputSet.msg.email-exist", args));
return;
}
user.setFirstName(uiForm.getUIStringInput("firstName").getValue());
user.setLastName(uiForm.getUIStringInput("lastName").getValue());
user.setDisplayName(uiForm.getUIStringInput("displayName").getValue());
user.setEmail(newEmail);
uiApp.addMessage(new ApplicationMessage("UIAccountProfiles.msg.update.success", null));
service.getUserHandler().saveUser(user, true);
state.setAttribute(CacheUserProfileFilter.USER_PROFILE, user);
UIWorkingWorkspace uiWorkingWS = Util.getUIPortalApplication().getChild(UIWorkingWorkspace.class);
uiWorkingWS.updatePortletsByName("UserInfoPortlet");
uiWorkingWS.updatePortletsByName("OrganizationPortlet");