Dear Wob,
(fan of Looney Tunes?)
Like you I think that the form-based Dialogs with validation and co are one of the major selling points of Spring RC.
I am also interested in having such a form put in an internal frame... rather than a modal dialog!
I have had a quick look and it seems that this functionality (form/validation messages/button bar) can only be in a Dialog.
I cannot understand why it is the case...
I think I may have a workaround... and I would like this to be validated by the community, in case it is just too dirty...
I have written the quintessential Bean/View/Form example which I will include below (there are quite a few bits to it...)
I have reached the point where I can create a dialog that can be displayed in an internal frame with all bits working.
Here is the dialog form:

and when it is displayed part of an internal frame:

So, it is great? Not quite...
1/ I need to create the dialog as usual, it even instantiate a dialog
2/ I put in the internal frame the ContentPane of the dialog, not the dialog itself as a swing Container cannot accept
a window. In order add it I do view.add(dialog.getDialog().getContentPane()) and return view from View.createControl().
3/ but the true issue is that getDialog() will return null... unless you call showDialog() which displays it as a dialog!!!
This is due to the fact that ApplicationDialog calls createDialog() only in showDialog().
Would it be possible to change it? Say getDialog() could call createDialog() if dialog is null?
I think that may be the simplest way... What do the committers think?
Alternatively, the functionality of form with validation / messages / buttons could be refactored to be independent from a JDialog
and allow it to be placed in either JDialog or JInternalFrame... But that would be longer term I guess...
As promised, here is the code:
The Bean: Test.java
Code:
public class Test {
private String name;
private String address;
private String city;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Test(String name, String address, String city) {
this.address = address;
this.city = city;
this.name = name;
}
}
The View:
Code:
import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import org.springframework.binding.form.ValidatingFormModel;
import org.springframework.richclient.dialog.TabbedDialogPage;
import org.springframework.richclient.dialog.TitledPageApplicationDialog;
import org.springframework.richclient.form.FormModelHelper;
public class TestView extends AbstractView {
protected JComponent createControl() {
JPanel view = new JPanel(new BorderLayout());
// create a form and try to add it to the view...
ValidatingFormModel model = FormModelHelper.createFormModel(new Test("Benoit","Docklands","London"));
TestForm form = new TestForm(model);
TabbedDialogPage compositePage = new TabbedDialogPage("testForm");
compositePage.addForm(form);
TitledPageApplicationDialog dialog = new TitledPageApplicationDialog(compositePage, getWindowControl()) {
protected boolean onFinish() {
return true;
}
};
System.out.println("DIALOG 1 --> " + dialog.getDialog());
dialog.showDialog();
System.out.println("DIALOG 2 --> " + dialog.getDialog());
view.add(dialog.getDialog().getContentPane(),BorderLayout.CENTER);
return view;
}
}
The Form
Code:
import javax.swing.JComponent;
import org.springframework.binding.form.FormModel;
import org.springframework.richclient.form.AbstractForm;
import org.springframework.richclient.form.binding.swing.SwingBindingFactory;
import org.springframework.richclient.form.builder.TableFormBuilder;
public class TestForm extends AbstractForm {
public TestForm(final FormModel formModel) {
super(formModel, "testForm");
}
protected JComponent createFormControl() {
TableFormBuilder formBuilder = new TableFormBuilder(getBindingFactory());
SwingBindingFactory bindingFactory = (SwingBindingFactory) getBindingFactory();
formBuilder.add("name");
formBuilder.row();
formBuilder.add("address");
formBuilder.row();
formBuilder.add("city");
return formBuilder.getForm();
}
}
messages.properties
Code:
##
# TEST VIEW
##
testView.label=Test
# Caption is used for the TOOLBAR!
testView.caption=Test
testForm.title=Test Form
testForm.testForm.title=Test Page
testForm.name.label=Name
testForm.address.label=Address
testForm.name.displayName=the name
The Validating rule: (add it in your DefaultRulesSource)
Code:
private Rules createTestRules() {
return new Rules(Test.class) {
protected void initRules() {
add("name", all(
new Constraint[] {
required(),
maxLength(15),
regexp("[a-zA-Z -]*",
"alphabetic") }));
}
};
}
the -context.xml Test added to the File Menu
Code:
<bean id="showTestViewCommand" class="org.springframework.richclient.command.support.ShowViewCommand">
<property name="viewDescriptor">
<ref bean="testView"/>
</property>
</bean>
<bean id="fileMenu"
class="org.springframework.richclient.command.CommandGroupFactoryBean">
<property name="members">
<list>
<value>showTestViewCommand</value>
</list>
</property>
</bean>
the -application-context.xml
Code:
<bean id="testView"
class="org.springframework.richclient.application.support.DefaultViewDescriptor">
<property name="viewClass">
<value>TestView</value>
</property>
</property>
</bean>
Et voila!
So the remaining questions are:
1/ Is this ok???
2/ Can the ApplicationDialog be modified, say getDialog() to call createDialog() if it is null.
Or give a way to create it from outside.
3/ Shall I put this in a wiki page?
4/ I shall raise a JIRA for modifying the ApplicationDialog after I test a few things.
Hope this helps!
Let me know
best regards
Benoit