While I waiting for CVS propagate to anonymous, I tried adding gt() constraint to Integer property. I made it > 5. If I type 6, no validation error message in dialog message area as expected (good). If I type 5, I see message "<my property> must be greater than 5" as expected (good). Problem is, if I type say "6a", I see cryptic message in dialog message area: "<my property> org.springframework.binding.form.support.Validatin gFormModel". I also see this in log (console): "[INFO,ValidatingFormModel,AWT-EventQueue-0] Illegal argument exception occured setting value"
I think to myself, okay Stefano, let's try making regex constraint for only numeric characters. So I try adding this constraint:
As can see, is very similar to this regex example from Petclinic:Code:regexp("[0-9]*", "numeric")
So I think, good this will work. Problem is, when I try to execute dialog, I get ClassCastException in RegexpConstraint.test(). Here is full stack trace, if helps:Code:regexp("[a-zA-Z]*", "alphabetic")
Indeed, when I use debugger, I inspect "argument" parameter to RegexpConstraint.test() and is Integer but cast is for CharSequence. So that is why ClassCastException, obviously.Code:[ERROR,ApplicationAdvisor,AWT-EventQueue-0] java.lang.reflect.InvocationTargetException java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:231) at org.springframework.rules.reporting.BeanValidationResultsCollector.collectPropertyResultsInternal(BeanValidationResultsCollector.java:73) at org.springframework.rules.reporting.BeanValidationResultsCollector.collectPropertyResults(BeanValidationResultsCollector.java:67) at org.springframework.binding.form.support.ValidatingFormModel$ValidatingFormValueModel.validatePropertyConstraint(ValidatingFormModel.java:298) at org.springframework.binding.form.support.ValidatingFormModel.validate(ValidatingFormModel.java:432) at org.springframework.richclient.forms.SwingFormModel.validate(SwingFormModel.java:863) at org.springframework.richclient.dialog.FormBackedDialogPage.createControl(FormBackedDialogPage.java:72) at org.springframework.richclient.dialog.AbstractDialogPage$1.createControl(AbstractDialogPage.java:49) at org.springframework.richclient.factory.AbstractControlFactory.getControl(AbstractControlFactory.java:48) at org.springframework.richclient.dialog.AbstractDialogPage.getControl(AbstractDialogPage.java:215) at org.springframework.richclient.dialog.TitledPageApplicationDialog.createTitledDialogContentPane(TitledPageApplicationDialog.java:69) at org.springframework.richclient.dialog.TitledApplicationDialog.createDialogContentPane(TitledApplicationDialog.java:132) at org.springframework.richclient.dialog.TitledApplicationDialog.addDialogComponents(TitledApplicationDialog.java:121) at org.springframework.richclient.dialog.ApplicationDialog.createDialog(ApplicationDialog.java:288) at org.springframework.richclient.dialog.ApplicationDialog.showDialog(ApplicationDialog.java:257) at stefano.example.ui.MyView$PropertiesCommandExecutor.execute(MyView.java:477) at org.springframework.richclient.command.support.AbstractActionCommandExecutor.execute(AbstractActionCommandExecutor.java:51) at org.springframework.richclient.command.TargetableActionCommand.doExecuteCommand(TargetableActionCommand.java:97) at org.springframework.richclient.command.ActionCommand.execute(ActionCommand.java:188) at org.springframework.richclient.command.ActionCommand$1.actionPerformed(ActionCommand.java:123) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257) at javax.swing.AbstractButton.doClick(AbstractButton.java:289) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113) at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943) at java.awt.Component.processMouseEvent(Component.java:5134) at java.awt.Component.processEvent(Component.java:4931) at java.awt.Container.processEvent(Container.java:1566) at java.awt.Component.dispatchEventImpl(Component.java:3639) at java.awt.Container.dispatchEventImpl(Container.java:1623) at java.awt.Component.dispatchEvent(Component.java:3480) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095) at java.awt.Container.dispatchEventImpl(Container.java:1609) at java.awt.Window.dispatchEventImpl(Window.java:1590) at java.awt.Component.dispatchEvent(Component.java:3480) at java.awt.EventQueue.dispatchEvent(EventQueue.java:450) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136) at java.awt.EventDispatchThread.run(EventDispatchThread.java:99) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:224) ... 45 more Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:231) at org.springframework.rules.reporting.BeanValidationResultsCollector.visit(BeanValidationResultsCollector.java:89) ... 50 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:224) ... 51 more Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:231) at org.springframework.rules.reporting.ValidationResultsCollector.visit(ValidationResultsCollector.java:90) ... 56 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:224) ... 57 more Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:231) at org.springframework.rules.reporting.BeanValidationResultsCollector.visit(BeanValidationResultsCollector.java:122) ... 62 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:224) ... 63 more Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:231) at org.springframework.rules.reporting.ValidationResultsCollector.visit(ValidationResultsCollector.java:90) ... 68 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit(ReflectiveVisitorSupport.java:224) ... 69 more Caused by: java.lang.ClassCastException at org.springframework.rules.constraint.RegexpConstraint.test(RegexpConstraint.java:49) at org.springframework.rules.reporting.ValidationResultsCollector.visit(ValidationResultsCollector.java:161) at org.springframework.rules.reporting.BeanValidationResultsCollector.visit(BeanValidationResultsCollector.java:126) ... 73 more
So, thinking I do something wrong, I try adding my numeric constraint to a String property instead of Integer. In this case, when I type "6a", I see proper message in dialog message area: "<my property> must consist of numeric characters only".
So, perhaps regex is only working for String properties right now but maybe it should be changed for supporting other types. If not, please tell how to apply constraints to Integer property that will give nice validation error message in dialog if user tries typing non-numeric character?


Reply With Quote