Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Integer Constraints in RulesSource?

  1. #11

    Default

    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:
    Code:
    regexp&#40;"&#91;0-9&#93;*", "numeric"&#41;
    As can see, is very similar to this regex example from Petclinic:
    Code:
    regexp&#40;"&#91;a-zA-Z&#93;*", "alphabetic"&#41;
    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:
    &#91;ERROR,ApplicationAdvisor,AWT-EventQueue-0&#93; java.lang.reflect.InvocationTargetException
    java.lang.RuntimeException&#58; java.lang.reflect.InvocationTargetException
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;231&#41;
    	at org.springframework.rules.reporting.BeanValidationResultsCollector.collectPropertyResultsInternal&#40;BeanValidationResultsCollector.java&#58;73&#41;
    	at org.springframework.rules.reporting.BeanValidationResultsCollector.collectPropertyResults&#40;BeanValidationResultsCollector.java&#58;67&#41;
    	at org.springframework.binding.form.support.ValidatingFormModel$ValidatingFormValueModel.validatePropertyConstraint&#40;ValidatingFormModel.java&#58;298&#41;
    	at org.springframework.binding.form.support.ValidatingFormModel.validate&#40;ValidatingFormModel.java&#58;432&#41;
    	at org.springframework.richclient.forms.SwingFormModel.validate&#40;SwingFormModel.java&#58;863&#41;
    	at org.springframework.richclient.dialog.FormBackedDialogPage.createControl&#40;FormBackedDialogPage.java&#58;72&#41;
    	at org.springframework.richclient.dialog.AbstractDialogPage$1.createControl&#40;AbstractDialogPage.java&#58;49&#41;
    	at org.springframework.richclient.factory.AbstractControlFactory.getControl&#40;AbstractControlFactory.java&#58;48&#41;
    	at org.springframework.richclient.dialog.AbstractDialogPage.getControl&#40;AbstractDialogPage.java&#58;215&#41;
    	at org.springframework.richclient.dialog.TitledPageApplicationDialog.createTitledDialogContentPane&#40;TitledPageApplicationDialog.java&#58;69&#41;
    	at org.springframework.richclient.dialog.TitledApplicationDialog.createDialogContentPane&#40;TitledApplicationDialog.java&#58;132&#41;
    	at org.springframework.richclient.dialog.TitledApplicationDialog.addDialogComponents&#40;TitledApplicationDialog.java&#58;121&#41;
    	at org.springframework.richclient.dialog.ApplicationDialog.createDialog&#40;ApplicationDialog.java&#58;288&#41;
    	at org.springframework.richclient.dialog.ApplicationDialog.showDialog&#40;ApplicationDialog.java&#58;257&#41;
    	at stefano.example.ui.MyView$PropertiesCommandExecutor.execute&#40;MyView.java&#58;477&#41;
    	at org.springframework.richclient.command.support.AbstractActionCommandExecutor.execute&#40;AbstractActionCommandExecutor.java&#58;51&#41;
    	at org.springframework.richclient.command.TargetableActionCommand.doExecuteCommand&#40;TargetableActionCommand.java&#58;97&#41;
    	at org.springframework.richclient.command.ActionCommand.execute&#40;ActionCommand.java&#58;188&#41;
    	at org.springframework.richclient.command.ActionCommand$1.actionPerformed&#40;ActionCommand.java&#58;123&#41;
    	at javax.swing.AbstractButton.fireActionPerformed&#40;AbstractButton.java&#58;1764&#41;
    	at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed&#40;AbstractButton.java&#58;1817&#41;
    	at javax.swing.DefaultButtonModel.fireActionPerformed&#40;DefaultButtonModel.java&#58;419&#41;
    	at javax.swing.DefaultButtonModel.setPressed&#40;DefaultButtonModel.java&#58;257&#41;
    	at javax.swing.AbstractButton.doClick&#40;AbstractButton.java&#58;289&#41;
    	at javax.swing.plaf.basic.BasicMenuItemUI.doClick&#40;BasicMenuItemUI.java&#58;1113&#41;
    	at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased&#40;BasicMenuItemUI.java&#58;943&#41;
    	at java.awt.Component.processMouseEvent&#40;Component.java&#58;5134&#41;
    	at java.awt.Component.processEvent&#40;Component.java&#58;4931&#41;
    	at java.awt.Container.processEvent&#40;Container.java&#58;1566&#41;
    	at java.awt.Component.dispatchEventImpl&#40;Component.java&#58;3639&#41;
    	at java.awt.Container.dispatchEventImpl&#40;Container.java&#58;1623&#41;
    	at java.awt.Component.dispatchEvent&#40;Component.java&#58;3480&#41;
    	at java.awt.LightweightDispatcher.retargetMouseEvent&#40;Container.java&#58;3450&#41;
    	at java.awt.LightweightDispatcher.processMouseEvent&#40;Container.java&#58;3165&#41;
    	at java.awt.LightweightDispatcher.dispatchEvent&#40;Container.java&#58;3095&#41;
    	at java.awt.Container.dispatchEventImpl&#40;Container.java&#58;1609&#41;
    	at java.awt.Window.dispatchEventImpl&#40;Window.java&#58;1590&#41;
    	at java.awt.Component.dispatchEvent&#40;Component.java&#58;3480&#41;
    	at java.awt.EventQueue.dispatchEvent&#40;EventQueue.java&#58;450&#41;
    	at java.awt.EventDispatchThread.pumpOneEventForHierarchy&#40;EventDispatchThread.java&#58;197&#41;
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy&#40;EventDispatchThread.java&#58;150&#41;
    	at java.awt.EventDispatchThread.pumpEvents&#40;EventDispatchThread.java&#58;144&#41;
    	at java.awt.EventDispatchThread.pumpEvents&#40;EventDispatchThread.java&#58;136&#41;
    	at java.awt.EventDispatchThread.run&#40;EventDispatchThread.java&#58;99&#41;
    Caused by&#58; java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;224&#41;
    	... 45 more
    Caused by&#58; java.lang.RuntimeException&#58; java.lang.reflect.InvocationTargetException
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;231&#41;
    	at org.springframework.rules.reporting.BeanValidationResultsCollector.visit&#40;BeanValidationResultsCollector.java&#58;89&#41;
    	... 50 more
    Caused by&#58; java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;224&#41;
    	... 51 more
    Caused by&#58; java.lang.RuntimeException&#58; java.lang.reflect.InvocationTargetException
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;231&#41;
    	at org.springframework.rules.reporting.ValidationResultsCollector.visit&#40;ValidationResultsCollector.java&#58;90&#41;
    	... 56 more
    Caused by&#58; java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;224&#41;
    	... 57 more
    Caused by&#58; java.lang.RuntimeException&#58; java.lang.reflect.InvocationTargetException
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;231&#41;
    	at org.springframework.rules.reporting.BeanValidationResultsCollector.visit&#40;BeanValidationResultsCollector.java&#58;122&#41;
    	... 62 more
    Caused by&#58; java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;224&#41;
    	... 63 more
    Caused by&#58; java.lang.RuntimeException&#58; java.lang.reflect.InvocationTargetException
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;231&#41;
    	at org.springframework.rules.reporting.ValidationResultsCollector.visit&#40;ValidationResultsCollector.java&#58;90&#41;
    	... 68 more
    Caused by&#58; java.lang.reflect.InvocationTargetException
    	at sun.reflect.GeneratedMethodAccessor23.invoke&#40;Unknown Source&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
    	at org.springframework.util.visitor.ReflectiveVisitorSupport.invokeVisit&#40;ReflectiveVisitorSupport.java&#58;224&#41;
    	... 69 more
    Caused by&#58; java.lang.ClassCastException
    	at org.springframework.rules.constraint.RegexpConstraint.test&#40;RegexpConstraint.java&#58;49&#41;
    	at org.springframework.rules.reporting.ValidationResultsCollector.visit&#40;ValidationResultsCollector.java&#58;161&#41;
    	at org.springframework.rules.reporting.BeanValidationResultsCollector.visit&#40;BeanValidationResultsCollector.java&#58;126&#41;
    	... 73 more
    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.

    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?
    Stefano Rossi

    "If I want your opinion, I'll give it to you."

  2. #12
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Well, regexps are designed to work on strings, not ints. A interesting possibility though. Would it make sense to try to convert the int to a string using the String.valueOf() method in the regexp test...

    The problem is the reporting system needs some work ;-)

    I'll see about addressing your problem!
    Keith Donald
    Core Spring Development Team

  3. #13

    Default

    Quote Originally Posted by kdonald
    Well, regexps are designed to work on strings, not ints.
    Yes but I guess I thinking that int is String while in JTextField. Maybe regex() constraints should be tried first before you try to convert String in the JTextField to the type of the bound property?

    Quote Originally Posted by kdonald
    The problem is the reporting system needs some work
    Oh, you're too humble. You are doing great job really! Keep it up!
    Stefano Rossi

    "If I want your opinion, I'll give it to you."

  4. #14
    Join Date
    Aug 2004
    Posts
    16

    Default

    I'm not really comfortable with trying to apply regexs to numbers... RegExs are great for working with Strings, and they are meant entirely for Strings. There's a seperate set of operations that are appropriate for other kinds of data.

    The better way to address the specific example you gave is to have a text field that simply only accepts numeric input (via a JFormattedTextField or the like). In fact, when SwingModelForm creates a control for a Numeric property, it should return a text field that only accepts numeric data... (Which I should just write and submit into the code instead of continually griping about, but.... :| )

Similar Threads

  1. JdbcTemplate and Integer Columns
    By jkookie in forum Data
    Replies: 3
    Last Post: Aug 9th, 2005, 09:58 AM
  2. Replies: 6
    Last Post: May 30th, 2005, 07:11 AM
  3. Replies: 2
    Last Post: Nov 5th, 2004, 03:47 PM
  4. Boolean, Date, Integer Fields on Form
    By steve_smith in forum Swing
    Replies: 2
    Last Post: Oct 27th, 2004, 01:34 AM
  5. PropertyEditorRegistry, RulesSource, ...
    By besbello in forum Swing
    Replies: 2
    Last Post: Aug 30th, 2004, 05:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •