reset password
Author Message
kknaur
Posts: 540
Posted 17:43 Oct 30, 2010 |

I understand how to use the Spring MVC to handle requests through a Controller, creating the Model, and then using the ModelAndView to display the results.  What I am having trouble understanding, is how do you go from a View (with some parameters), back to a Controller. In other words, going from a JSP page back to a Controller with some additional information.  The example that comes to mind, is when a User clicks on a folder in a View and that View passes some information about that folder to a Controller so the Controller can get the underlying files, and then send that information back to the View to redisplay the contents of the new folder.  In my previous assignment, I simply passed the name for the folder in the URL and used this information to create the display, but I am not sure how to do this in the context of the Spring MVC.  Is there any material that I can look at or an example that I can refer to, to help me understand this concept?

alomo
Posts: 70
Posted 19:03 Oct 30, 2010 |

Those requests that you understand how to handle through a Controller - how do you think did they get to that specific Controller? Every request shall be mapped to the proper controller.

kknaur
Posts: 540
Posted 20:53 Oct 30, 2010 |

Yes...but how do you go from a View to a Controller with additional information added by the View....I didn't really understand your response.

Last edited by kknaur at 20:54 Oct 30, 2010.
alomo
Posts: 70
Posted 21:51 Oct 30, 2010 |

I am not sure that we are on the same page. The "additional information" from a View will be (shall be) in the Request. So in the Controller you can access that information from the Request, and based on that information some particular ModelAndView could be created and returned. I hope that makes sense. I am a bit confused with your question because you said that you "understand how to use the Spring MVC to handle requests through a Controller..."

kknaur
Posts: 540
Posted 00:16 Oct 31, 2010 |

Ok, so the overall flow idea I have for a Controller / View that displays a list of files and folder is like this.  The user navigates to the URL of the Controller that will by default grab the base directory of where the user's files are located, access the database, and create some kind of list of the files and folders in the base directory. That list is passed to the ModelAndView and the ModelAndView is returned and then resolved to a View that will display those files and folder.  Now the folders will be hyperlinks that when clicked will send the request back to the Controller which will somehow know which folder is clicked so that it can find that folder and then create a list of files under THAT folder, then return a new ModelAndView which resolves to the View which will display the new list of files and folders.


The part I am confused on is how do I tell the controller WHICH folder to locate in the database to see what files are underneath that folder?  Do I just pass some parameters in the URL that goes back to the controller such as ?folder=folderName in the URL or is there a better way to handle this?


I may not be explaining myself very clearly so I'm sorry for the confusion.  Basically the View needs to tell the Controller which folder was clicked so the Controller will then know which folder the user wants to see the contents of. 

cysun
Posts: 2935
Posted 09:53 Oct 31, 2010 |
kknaur wrote:

...

The part I am confused on is how do I tell the controller WHICH folder to locate in the database to see what files are underneath that folder?  Do I just pass some parameters in the URL that goes back to the controller such as ?folder=folderName in the URL or is there a better way to handle this?

...

Yes, but instead of using folder name you should use file id.

Review and understand the user management example discussed in class. It's actually very similar to what you need to do for the homework:

display users -> display files/folders

add user -> create new folder / upload file

edit user -> rename

hyperlink for emailing a user -> hyperlink for displaying a folder

...

kknaur
Posts: 540
Posted 10:33 Oct 31, 2010 |

Thank you this helps a lot!