[jboss-user] [JBoss Seam] - Re: DataModel
tony.herstell@gmail.com
do-not-reply at jboss.com
Sat Feb 10 15:22:46 EST 2007
I had a similar problem.
My "Find" Session Sateful bean had a liost of users.
My Controller Stateful conversational fiddled with the store of users.
When my Controller update the database; this was "behind" the back of the "Find" bean; so it didnt get reflected to the "find" beans "em" cache.
My solution is below (Gavin may have a better way to do it; but this works for me)
(need to inject the "Find" bean into the crud Controller bean naturally)
| @End
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public String update() {
| log.info("> update");
| user.setPassword(encryptionController.encrypt(user.getPassword()));
| em.merge(user);
| em.flush();
| facesMessages.addFromResourceBundle("user_update_successful");
|
| /*
| * We need to update this user in the list of users in the session scoped FindUserController
| */
| if (findUserController != null) {
| log.info("User sent to database => " + user);
| findUserController.updateUserInExistingList(user);
| }
|
| log.info("< update");
| return "findUser";
| }
|
| public void updateUserInExistingList(User updatedUser) {
| log.info("> updateUserInExistingList");
| List<User> usersList = new ArrayList<User>();
| for (User eachUser : users) {
| if (updatedUser.getId() != eachUser.getId()) {
| usersList.add(eachUser);
| } else {
| em.refresh(eachUser); // Force the update of the user in the em cache.
| log.info("User from the DBase (refreshed) => " + eachUser);
| usersList.add(eachUser);
| }
| }
| users = usersList.toArray(new User[0]);
| applyCurrentQuery();
| log.info("< updateUserInExistingList");
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4014239#4014239
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4014239
More information about the jboss-user
mailing list