Skip to main content

Gooey Beans Form

Posted by evanx on December 29, 2006 at 7:03 AM PST

Gooey Beans Form

We use an MVC architecture, with some simple
"beans binding" from our form to our model.
Our "model" is a POJO, as in the
Presentation Model pattern.
We explicitly declare our properties in a model info class as presented earlier in
Gooey Beans Info.

In our controller we create "adapters" for the input components in our form,
eg. JTextField, JFormattedTextField, JCheckBox and JComboBox. Our form might be created
using Matisse, so we bind our adapters to our form's (private) input components
using reflection.

align="left" hspace="8"/>

style="text-decoration: none;">

Code Snippet

We implemented a
model object in Gooey Beans Info,
and a form in Group Layout Therapy.
We now implement the controller as follows.

public class PersonInfoController implements ActionListener, QGooeyWorksheet {    
    PersonInfoForm form = new PersonInfoForm();
    PersonInfoModel model = new PersonInfoModel();
    PersonInfoModelInfo modelInfo = new PersonInfoModelInfo();
    QGooeyFormHelper gooey =
            new QGooeyFormHelper(this, model);
    QTextFieldAdapter lastName =
    QFormattedTextFieldAdapter dependents =
    QCheckBoxAdapter confirmed =
    QComboBoxAdapter title =
    public PersonInfoController() {
    public void actionPerformed(ActionEvent event) {
        try {
            ... // process model
            gooey.publishInfo(Level.INFO, null);
        } catch (Exception e) {
            gooey.publishException(e, Level.WARNING, null);

where the component adapters are created with a bean property courtesy of our
"model info" class. They enable beans binding to our POJO presentation
model object. We provide methods to refresh our model from the form,
and visa versa, as seen in the above actionPerformed() method.

Our input component adapters are connected to the components on our form
using reflection, when we invoke setForm() in the above constructor.
If this form is created using Netbeans, then
those components are private. That's fine because we manipulate them in
our controller via the adapters.


We continue with the same demo as in the prequel
Gooey Beans Info.


  (PersonInfo, 150k/500k, unsandboxed, Java6)

src="" width="700" height="209"

style="text-decoration: none;">
style="text-decoration: none;">
style='text-decoration: none;'>
Related Topics >>