Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

How to create bean without instantiating it?

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody; I'm new here and in Java.

I am writing my first simple application and couldn't find the proper way to declare bean, that shouldn't be instantiated on app startup. My case is:
I have a main window, where is button that opens another window - for now it's ok.
I want another window (where the user will fill the data and send some to main window) opening from it. When I declare bean with another window both windows appears on startup.
Shouldn't I declare bean for that window (so for what is that XML file? Only for main frame?)
Should I create another XML file?
Should I set some property for such bean?
Saloon Keeper
Posts: 12023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just instantiate the new window from the old window's code? No intervention from the IoC container needed.
Saloon Keeper
Posts: 22122
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Matt.

In Spring, beans are not instantiated by default until you request them from the bean factory. Also, I think you have the terms "define" and "create" confused. We use the term "create" and "instantiate" to mean essentially the same thing - instantiate is just the more formal term.

Also, from the sound of it, you want your app to display a (probably modal) dialog, not merely "open a window". A dialog is a special type of window, generally used for data entry or user approval as a pop-up object that, once its task is done is dismissed, leaving the primary application window(s).

Most commonly when I do that sort of thing, I create a GUI Model object (bean), which can be managed by the Spring bean factory. The data entry dialog(s) - sometimes there will be a whole series of them, like with a "wizard" - then display such data as was pre-initialized in the bean and accept changes made in the dialog to the bean. There may even be a shadow bean behind the data-entry Model if you implement a "revert" function to undo all changes made in the dialog.

Once the GUI Model bean is created, I create a View and link it via Controllers to the Mode, which gives me the classic Model/View/Controller (MVC) construct.

To dismiss the process, there's usually an OK and Cancel buttons. The OK button dismisses the dialog window and copies data from the Model bean into the main working storage of the app - sometimes this involves writing that data out to a persistent storage (file or database, for example). The Cancel button likewise dismisses the dialog window, but it then discards the Model bean without bothering to copy data from it first.
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic