• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Optional SessionAttributes / controlling flow between optional URLs  RSS feed

Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the confusing thread title... I'm not sure how to summarize my question. I'm trying to figure out how to write my Spring mvc controller so that in certain cases the controller returns the user to a previous url instead of the default url/view. So let me explain. I have an app with user accounts and clients for the business I'm creating the app for. So lets say the admin user wants to add a new user account and the new user represents a client that is also new. I'd like the admin to be able to go from editing new user info to editing new client info and then return to editing the user where he could then set the newly created client as the one that the new user represents. The point being that the normal path from editing a new client is to a view showing a list of clients.

I have run into this in several situations, needing to control the flow of the app in this kind of spots. So I'd like to ask whats the default/best option for accomplishing this?

I was thinking I could just use a SessionAttribute like boolean returnToEditUser while going through editing the new client info and if the attribute is set to 'true' the controller method responsible for saving the new client info would redirect to editing the new user. Or maybe set the redirect address as a SessionAttribute so that this would work for redirecting to several urls: However, this would seem to require the attribute to be always present for the methods doing the editing and saving of the client. It would have to be set in all cases where the user edits client info, no? Maybe it isn't a huge issue but it doesn't seem very eloquent. There is a way of making the attribute optional or setting a default value?

Edit: oh wait, SessionAttribute wont work since if the user aborts editing and goes to the home page of the app, the attribute will cause a problem later if he returns to the page for editing client account info...

Edit2: since i used the word 'flow' in my post, is this something that Spring Web Flow is for and if so, could this be relatively simply done with it?
Posts: 2759
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you figured right.

If you want to store state between requests, you can do this it with Spring MVC by storing state in Session. However, Spring Webflow is better suited because it makes it easier. It provides the concept of "flow" and there is a scope assosciated with it. You can store state in flow scope, and the state lives with the flow.
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!