Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Difference between modelAttribute and session Attribute

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Elezabeth Gregory
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know the difference between modelAttribute and session Attribute. What is the relationship between a session and a model.. Please explain... Thanks in Advance
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Elezabeth, Welcome to JavaRanch!

Can you bring more context to model Attribute and session Attribute? Where do you see these things, are they in a framework or are you talking Java EE? Those terms can be rather generic, so providing more details about where you see them may provide more better answers.

 
Elezabeth Gregory
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Steve.


I will explain the context. We have designed an application where you can book the flight Tickets and our application has two kinds of Users- Online user and Marketing User(this user has a login Id and password with which he can login into the application. Something like an Admin user.)

So for using some variables across all the pages , we are putting some variables like language code, region name etc in session .

And also , we are setting some variables in model also like this .

model.addAttribute("fareVO", fareVO).

What I need to know is , what is the difference between storing in a session and adding it in a model ?
Why should I use both ? Is there any relationship between setting in a session and setting in a model? Or is both settings are different?

Hope this would explain my question .

Thanks in Advance
Elz
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is still awfully sparse on details. I will assume you are creating a web application.

A session is generally a context shared by a single user across multiple pages in a web application. I have no clue what your model object is, it is not a generic Java object, so I can't tell you what it does or how it might be different than the session. Generally speaking, in an MVC framework, the Model manages behavior and data. Conceptually I think of the session as part of the Model layer in an MVC application. In your case I would believe that the model object probably provides more application specific storage, maybe provides a chance for your application to react to the data you store in it, and might provide a bridge between the View (web part) of the application and the rest of the Model (business logic) part of the application. If this is true, then the session would be used to store View & Control parts of the application data (those parts required to properly display pages, control page / view flow) and the model object would be used to store application specific business related data (ticketing information, fare and seat data, database configs...).

To figure out how the two objects are different you should research about what type the model object is, where it is created, where it gets stored, and where it gets used. To learn more about the session object, any JavaEE tutorial or book will do.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic