This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Data Model Design  RSS feed

 
Ashwin Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Swings..and I am working on Swing application >> it has Module1, Module2, Module3. I am working on Module3, For which I designed three Panels in one class, each screen has back and next buttons and some radio buttons and text boxes, In this scenario by going back and forth the data is maintained. I have link for other model go back..when I come back to my module the data is lost..because I am creating new instance of my class. How do I store the data throgh out the session ??..or how to approach this problem ??
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You make all of your views reference the same model object.
 
Ashwin Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please bit elaborate your answer !!, thanks
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you have three "views" of the same type of data, right? Each view shows different parts (or properties) of the data, right? What you need to do is make sure that each of your views is showing data from the same exact object as you traverse back and forth between them. In short, don't reinstantiate your model each time your view is shown.
[ May 05, 2005: Message edited by: James Carman ]
 
Ashwin Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the three modules have diffrent data and here is the flow: once the user finishes module 1 assessment(4 screens) >> moves to module 2 (3 screens) >> module 3 (2 screens).
So once module 1 finishes the data gets saved to the database. ok, so while iam in module3(say entered some data) and i can go back to module 1. when iam back to module 3 the data is lost. i am not using any model to store the data. how can I do that?/
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the problem with what you want to do and this depends on what happens with modeul1 when you go back to module3. You can't think *sessions* in desktop applications. You need to remember that you can only store information so many ways. So lets look at those ways..

  • JavaBean/Memory
  • Database
  • File System


  • JavaBean/Memory - Your model that holds your data should be some sort of a JavaBean when working with it. That will make things easier. The problem is that when your javabean goes out of scope, the widget holding on to it is disposed, it's up for gargage collection. So you can't guarntee that it will be there when you get back to your said module. On the other hand, if you just hide said module and never dispose it you should be ok with the javabean staying in memory.

    I only mentioned Database and File System because those were other options. You *could* store the temoray model data in the database when you need to and then retrieve it. You could do the same thing by serializing the data to the file system. In fact, you could serialize the actual model (javabean) and read it right back as that model. These might not be good options though.

    Like I said, you can't really think Sessions in desktop applications. But think about this. Web App Sessions are just seralized java objects in memory or on disk or in a database. Hmm, sound familiar.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!