Hey ok so I'm kind of relighting a previous thread (Quite old 2004).
I posted on it, but yet no record..
http://forum.springframework.org/showthread.php?t=11756
So I'm starting a new one. Bare with this post
I'm sure spring users would love to be able to do this in the future.
I'm using Spring MVC 2.5.6, Hibernate 3.4.0GA and integrating Spring Sercurity 2.0.0 soon. But I'm not to sure on SiteMesh or Tiles?
So I would like to be able to use multiple domain objects on a single
controller so i can see different lists associated with the user.
Like the users details and then the products, friends, comments that are associated to that user on one page.
-----------------------------------------------------------------------
========
METHOD 1
========
One page: User.html
-----------------------------------------------------------------------
On it I would like to call information from 4 controllers based on the userId.
User => UserDao => UserDaoImpl => UserService => UserServiceImpl => UserController
call a userId to get a user row
UserDaoImpl
-----------------------------------------------------------------------Code:public User getUser(int userId){ return (User)getHibernateTemplate().get(User.class, userId); }
I also have 3 other controllers
Product => ProductDao => ProductDaoImpl => ProductService => Product ServiceImpl => ProductController
Comments => CommentsDao => CommentsDaoImpl .............etc
Friends => ............etc
Based on the userId I would like to get the associated Objects/Maps from the Product, Comments and Friends tables in the Database.
From the controllers I would like to be able to do something like
But I know thats impossible as You can only wire/@AutowireCode:User user = userService.findUserById(userId); .. Product product = productService.findProductsById(userId); .. Comment comment = commentService.findCommentsById(userId); .. Friends friends = friendsService.findFriendsById(userId); ... ... model.put ( "userDetails", user); model.put ("productList", products); model.put ("commentList", comments); model.put ("friendsList", friends);
one service object to a Controller.
-----------------------------------------------------------------------
========
METHOD 2
========
HomePageContoller??
-----------------------------------------------------------------------
Make a new controller that ties in all the information I want and
then send it to the view
If I was to make a temporary table that got all the user information
and associated products, comments, friends,
I could use a HQL/SQL JOIN to form all the information
I'm not the best at HQL, so i'll give you what I Think it would be like in SQL
correct me if I'm wrong.
So '?' would be the userId that I want to find all this information from.Code:SELECT U.USERNAME, U.FIRST_NAME, U.SECOND_NAME, U.AGE, U.EMAIL, P.TITLE, P.DESCRIPTION, P.DATE, F.FRIENDS, C.COMMENTS FROM USERS U, PRODUCTS P, FRIENDS F, COMMENTS C WHERE U.ID = P.USER_ID AND U.ID = P.USER_ID AND U.ID = F.USER_ID AND U.ID = C.USER_ID AND U.ID = ?
UserDaoImpl
But now I would have to make a HomeData???Code:public List<HomeData> listHomePageData(int userId) { String query = "SELECT U.USERNAME ....."; return getHibernateTemplate().find(query, userId); }
Returning all these into list
I don't know if thats the way it's done but Id love to hear some advice.Code:@Autowired private HomePageService homePageService; @RequestMapping(method=RequestMethod.GET) public void listUserDeatils(@RequestParam("id") Integer id, Map <String,Object> model) { model.put("allData", homePageService.listHomePageData(id)); } . .
Also would executing that query everytime a users calls that page effect the servers preformance .. too much to handle 1000's of times?
-------------------------------------------------------------------------
Thanks for reading!
And any help at all
Allan



Reply With Quote
