Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How to create bean without instantiating it?

 
Greenhorn
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: 10684
229
  • 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: 21139
134
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.
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!