View Full Version : Null sub-field in an AbstractForm control
Patrick Vanhuyse
Sep 22nd, 2004, 05:32 AM
I have the following Form :
public class XXX extends AbstractForm {
public XXX(SwingFormModel singlePageFormModel) {
super(singlePageFormModel);
}
public JComponent createFormControl() {
FormLayout layout = new FormLayout("left:pref, 5dlu, pref:grow");
BeanFormBuilder formBuilder = new JGoodiesBeanFormBuilder(getFormModel(), layout);
formBuilder.add("name");
formBuilder.add("country.name");
formBuilder.add("expression");
return formBuilder.getForm();
}
}
It works fine except when country is null. There is a NullPointerException.
What are the possibilities to change this behaviour ?
For example, when country is null, I want the country.name field displays a '-'.
Patrick
Keith Donald
Sep 22nd, 2004, 03:03 PM
We're working on making null handling customizable. Right now, as you noted, you get a null value in path exception. A workaround to this is to use NestingFormModels, but it's not as elegant. See the FormModelTests in org.springframework.binding for some examples of this.
We're thinking the following strategies:
1. If you encounter null, instantiate a fresh instance, don't disable form.
2. If you encounter null, disable the form / form field all together; on form enable, instantiate a fresh instance.
3. If you encounter null, stop navigating and return a null value - to be rendered based on the installed type converter (property editor): like a "-".
Any additional behaivior that would make sense for handling null property paths?
Patrick Vanhuyse
Sep 23rd, 2004, 04:36 AM
We're working on making null handling customizable. Right now, as you noted, you get a null value in path exception. A workaround to this is to use NestingFormModels, but it's not as elegant. See the FormModelTests in org.springframework.binding for some examples of this.
So I can't use the BeanFormBuilder anymore. I have to build all my components by hand.
Correct ?
2. If you encounter null, disable the form / form field all together; on form enable, instantiate a fresh instance.
What do you mean ?
Keith Donald
Sep 23rd, 2004, 08:00 AM
There are several other builders you may use in conjunction with the NestingFormModel support. See the new additions Ollie made to the org.springframework.richclient.form package. In general, we're still in fairly rapid development mode in this area so expect the code to continue to improve.
I'm sorry I wasn't more clear on the my null path suggestions; the first two points I made were in regard to a backing form object itself being set to null, not a property (potentially nested property) of a non-null form object. Currently, the default behaivior for setting the formObject to null is to disable the form model, triggering all form controls to be greyed out. We're going to add different strategies there; points #1 and #2 of my previous post.
I agree the appropriate thing to do for a null property path with a non-null form object is to render an appropriate null value indicator like "-".
One issue with your way of doing things I noticed: you're binding the "name" property to the text field, not the country object. You may want to consider using the methods of SwingFormModel that would allow you to bind to the "country" property, and use "country.name" as the rendered property. This would be perfect for displaying in a combo box with a list of the countries, and no country selected if the country property is null (which may be what you want anyway instead of a text field.)
Patrick Vanhuyse
Sep 23rd, 2004, 09:19 AM
You may want to consider using the methods of SwingFormModel that would allow you to bind to the "country" property, and use "country.name" as the rendered property.
I will look this closer.
Thank you.
m0ritz
Jul 30th, 2007, 03:50 AM
Does anyone know, whether there has been a progress on the issue of using nested properties,that could be null, in a form?
Thanks
Moritz
julicrack
Feb 1st, 2008, 12:58 PM
Hi all,
Any news regarding this post?
Regards
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.