Hi,
last few days I've played with an weird behaviour of some of my forms.
Based on the Simple Example I've created a GenderType (same as ContactType in the sample code) and a form analogous to ContactForm in the example displaying a gender as a combobox.
When I open my form and skip through all fields to OK button using a tab key (no matter weather any value is changed) and push OK button (either by pressing enter or clicking) I get an exception
Failed to convert property value of type [java.lang.String] to required type [cz.euromise.adamekJ.model.GenderType] for property 'sexType'
When I click the combobox, select a value and then click OK button, everything goes as expected, no exception is thrown. And the most weird thing is when I once manage to get over this exception, it will not appear again (until new restart of the program).
Is it possible that my code is somehow responsible for that? Or is there any workaround?
This behaviour was tested on more machines, all Windows XP, Sun Java 5, Spring 1.2.7, Spring RCP 0.1.0 release and svn version 1309.
cheers
kolisko
Form code (relevant parts)
Code:public class ContactForm extends AbstractForm { public static final String FORM_NAME = "contact"; private JComponent firstNameField; public ContactForm(FormModel formModel) { super(formModel, FORM_NAME); } protected JComponent createFormControl() { final SwingBindingFactory bf = (SwingBindingFactory) getBindingFactory(); TableFormBuilder formBuilder = new TableFormBuilder(bf); formBuilder.setLabelAttributes("colGrId=label colSpec=right:pref"); formBuilder.addSeparator("General"); formBuilder.row(); formBuilder.add("firstName"); formBuilder.add("sexType"); formBuilder.row(); return formBuilder.getForm(); } public boolean requestFocusInWindow() { return firstNameField.requestFocusInWindow(); }
Patient Code:
GenderType Code:Code:class Patient { private String firstName; private GenderType sex = GenderType.MALE; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public GenderType getSexType() { return sex; } public void setSexType(GenderType sex) { this.sex = sex; } }
Code:public class GenderType extends ShortCodedLabeledEnum { public static final GenderType MALE = new GenderType(0, "Male"); public static final GenderType FEMALE = new GenderType(1, "Female"); private GenderType(int code, String label ) { super(code, label); } public String toString() { return getLabel(); } }
Exception
The gode on line 122 in PatientPropertiesDialog.java isCode:(ApplicationDialog$1:352) - Exception occurred executing dialog finish command. org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [cz.euromise.adamekJ.model.GenderType] for property 'sexType' at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:951) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:692) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:572) at org.springframework.binding.support.BeanPropertyAccessStrategy$BeanPropertyValueModel.setValue(BeanPropertyAccessStrategy.java:259) at org.springframework.binding.value.support.AbstractValueModel.setValueSilently(AbstractValueModel.java:54) at org.springframework.binding.value.support.BufferedValueModel.commit(BufferedValueModel.java:197) at org.springframework.binding.value.support.BufferedValueModel$CommitTriggerHandler.commit(BufferedValueModel.java:264) at org.springframework.binding.value.CommitTrigger.commit(CommitTrigger.java:45) at org.springframework.binding.form.support.AbstractFormModel.doCommit(AbstractFormModel.java:491) at org.springframework.binding.form.support.AbstractFormModel.commit(AbstractFormModel.java:471) at cz.euromise.adamekJ.ui.PatientPropertiesDialog.onFinish(PatientPropertiesDialog.java:122) ...
formModel is of type ValidatingFormModelCode:formModel.commit();


Reply With Quote