Results 1 to 7 of 7

Thread: Problem on using "FileChecks" to validate File pro

  1. #1
    Join Date
    Oct 2004
    Location
    Vancouver, Canada
    Posts
    35

    Default Problem on using "FileChecks" to validate File pro

    Hi,

    I got a problem on using org.springframework.richclient.filechooser.FileChe cks constraint to validate my property which is "File" type.

    I have an Object as:

    Code:
    public class ParserConfig {		
    	private String parserId;
    	private File rawFile;
    	public void setRawFile(File rawFile) {
    		this.rawFile = rawFile;
    	}
    	public File getRawFile() {
    		return rawFile;
    	}
    ...
    }
    and a Form for user input:

    Code:
    public class RawFileForm extends AbstractForm {
        public static final String FORM_ID = "rawFilePage";
        public RawFileForm(FormModel formModel) {
            super(formModel, FORM_ID);
       }
    
       protected JComponent createFormControl() {
            TableFormBuilder formBuilder = new TableFormBuilder(getFormModel());
            formBuilder.add("rawFile");
            return formBuilder.getForm();
       }
    }
    So far this works very well. But when I added constraint to "rawFile" property as:

    Code:
    public class ParserConfigRulesSource extends DefaultRulesSource {
       private ParserManager parserManager;	
        public ParserConfigRulesSource(ParserManager manager) {
            super();
            this.parserManager = manager;
            addRules(createConfigRules());
        }
    
        private Rules createConfigRules() {
            return new Rules(ParserConfig.class) {
                protected void initRules() {
                    add("parserId", inGroup(parserManager.getPaserList().toArray()));
                    add("rawFile", required());
                    add("rawFile", new FileChecks.FileExists());
                }            
    }
    When I typed in the first character in text field of RawFileForm, I got the following exception:
    [ERROR,ApplicationAdvisor,AWT-EventQueue-0] java.lang.reflect.InvocationTargetException
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at org.springframework.util.visitor.ReflectiveVisitor Support.invokeVisit(ReflectiveVisitorSupport.java: 231)
    at org.springframework.rules.reporting.BeanValidation ResultsCollector.collectPropertyResultsInternal(Be anValidationResultsCollector.java:73)
    at org.springframework.rules.reporting.BeanValidation ResultsCollector.collectPropertyResults(BeanValida tionResultsCollector.java:67)
    at org.springframework.binding.form.support.Validatin gFormModel$ValidatingFormValueModel.validateProper tyConstraint(ValidatingFormModel.java:298)
    at org.springframework.binding.form.support.Validatin gFormModel$ValidatingFormValueModel.validate(Valid atingFormModel.java:280)
    at org.springframework.binding.form.support.Validatin gFormModel$ValidatingFormValueModel.setValue(Valid atingFormModel.java:274)
    at org.springframework.richclient.forms.AbstractValue Setter.componentValueChanged(AbstractValueSetter.j ava:46)
    at org.springframework.richclient.forms.AsYouTypeText ValueSetter.controlTextValueChanged(AsYouTypeTextV alueSetter.java:56)
    at org.springframework.richclient.forms.AsYouTypeText ValueSetter.insertUpdate(AsYouTypeTextValueSetter. java:47)
    at javax.swing.text.AbstractDocument.fireInsertUpdate (Unknown Source)
    at javax.swing.text.AbstractDocument.handleInsertStri ng(Unknown Source)
    at javax.swing.text.AbstractDocument.insertString(Unk nown Source)
    at javax.swing.text.PlainDocument.insertString(Unknow n Source)
    at javax.swing.text.AbstractDocument.replace(Unknown Source)
    at javax.swing.text.JTextComponent.replaceSelection(U nknown Source)
    at javax.swing.text.DefaultEditorKit$DefaultKeyTypedA ction.actionPerformed(Unknown Source)
    at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    at javax.swing.JComponent.processKeyBinding(Unknown Source)
    at javax.swing.JComponent.processKeyBindings(Unknown Source)
    at javax.swing.JComponent.processKeyEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unkn own Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent (Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.Dialog$1.run(Unknown Source)
    at java.awt.Dialog.show(Unknown Source)
    at java.awt.Component.show(Unknown Source)
    at java.awt.Component.setVisible(Unknown Source)
    at org.springframework.richclient.dialog.ApplicationD ialog.showDialog(ApplicationDialog.java:261)
    at com.sjv.parser.ui.parserWizard.execute(parserWizar d.java:54)
    at org.springframework.richclient.command.TargetableA ctionCommand.doExecuteCommand(TargetableActionComm and.java:100)
    at org.springframework.richclient.command.ActionComma nd.execute(ActionCommand.java:188)
    at org.springframework.richclient.command.ActionComma nd$1.actionPerformed(ActionCommand.java:123)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Did I do something wrong? Could somebody help? Thanks a lot
    Regards
    linwei

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

    Default

    Is that the only exception? Is there another exception it wraps? My bet is it's a class cast exception. I check on this.
    Keith Donald
    Core Spring Development Team

  3. #3
    Join Date
    Oct 2004
    Location
    Vancouver, Canada
    Posts
    35

    Default

    keith,

    You're right. The whole message is as below. ( ClassCastExcetion is at bottom. Thanks a lot.

    [ERROR,ApplicationAdvisor,AWT-EventQueue-0] java.lang.reflect.InvocationTargetException
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at org.springframework.util.visitor.ReflectiveVisitor Support.invokeVisit(ReflectiveVisitorSupport.java: 231)
    at org.springframework.rules.reporting.BeanValidation ResultsCollector.collectPropertyResultsInternal(Be anValidationResultsCollector.java:73)
    at org.springframework.rules.reporting.BeanValidation ResultsCollector.collectPropertyResults(BeanValida tionResultsCollector.java:67)
    at org.springframework.binding.form.support.Validatin gFormModel$ValidatingFormValueModel.validateProper tyConstraint(ValidatingFormModel.java:298)
    at org.springframework.binding.form.support.Validatin gFormModel$ValidatingFormValueModel.validate(Valid atingFormModel.java:280)
    at org.springframework.binding.form.support.Validatin gFormModel$ValidatingFormValueModel.setValue(Valid atingFormModel.java:274)
    at org.springframework.richclient.forms.AbstractValue Setter.componentValueChanged(AbstractValueSetter.j ava:46)
    at org.springframework.richclient.forms.AsYouTypeText ValueSetter.controlTextValueChanged(AsYouTypeTextV alueSetter.java:56)
    at org.springframework.richclient.forms.AsYouTypeText ValueSetter.insertUpdate(AsYouTypeTextValueSetter. java:47)
    at javax.swing.text.AbstractDocument.fireInsertUpdate (Unknown Source)
    at javax.swing.text.AbstractDocument.handleInsertStri ng(Unknown Source)
    at javax.swing.text.AbstractDocument.insertString(Unk nown Source)
    at javax.swing.text.PlainDocument.insertString(Unknow n Source)
    at javax.swing.text.AbstractDocument.replace(Unknown Source)
    at javax.swing.text.JTextComponent.replaceSelection(U nknown Source)
    at javax.swing.text.DefaultEditorKit$DefaultKeyTypedA ction.actionPerformed(Unknown Source)
    at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    at javax.swing.JComponent.processKeyBinding(Unknown Source)
    at javax.swing.JComponent.processKeyBindings(Unknown Source)
    at javax.swing.JComponent.processKeyEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unkn own Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent (Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.Dialog$1.run(Unknown Source)
    at java.awt.Dialog.show(Unknown Source)
    at java.awt.Component.show(Unknown Source)
    at java.awt.Component.setVisible(Unknown Source)
    at org.springframework.richclient.dialog.ApplicationD ialog.showDialog(ApplicationDialog.java:261)
    at com.sjv.parser.ui.parserWizard.execute(parserWizar d.java:54)
    at org.springframework.richclient.command.TargetableA ctionCommand.doExecuteCommand(TargetableActionComm and.java:100)
    at org.springframework.richclient.command.ActionComma nd.execute(ActionCommand.java:188)
    at org.springframework.richclient.command.ActionComma nd$1.actionPerformed(ActionCommand.java:123)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.util.visitor.ReflectiveVisitor Support.invokeVisit(ReflectiveVisitorSupport.java: 224)
    ... 71 more
    Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at org.springframework.util.visitor.ReflectiveVisitor Support.invokeVisit(ReflectiveVisitorSupport.java: 231)
    at org.springframework.rules.reporting.BeanValidation ResultsCollector.visit(BeanValidationResultsCollec tor.java:89)
    ... 76 more
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.util.visitor.ReflectiveVisitor Support.invokeVisit(ReflectiveVisitorSupport.java: 224)
    ... 77 more
    Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at org.springframework.util.visitor.ReflectiveVisitor Support.invokeVisit(ReflectiveVisitorSupport.java: 231)
    at org.springframework.rules.reporting.ValidationResu ltsCollector.visit(ValidationResultsCollector.java :90)
    ... 82 more
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.util.visitor.ReflectiveVisitor Support.invokeVisit(ReflectiveVisitorSupport.java: 224)
    ... 83 more
    Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at org.springframework.util.visitor.ReflectiveVisitor Support.invokeVisit(ReflectiveVisitorSupport.java: 231)
    at org.springframework.rules.reporting.BeanValidation ResultsCollector.visit(BeanValidationResultsCollec tor.java:122)
    ... 88 more
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.util.visitor.ReflectiveVisitor Support.invokeVisit(ReflectiveVisitorSupport.java: 224)
    ... 89 more
    Caused by: java.lang.ClassCastException: java.lang.String
    at org.springframework.richclient.filechooser.FileChe cks$FileExists.test(FileChecks.java:50)
    at org.springframework.rules.reporting.ValidationResu ltsCollector.visit(ValidationResultsCollector.java :161)
    at org.springframework.rules.reporting.BeanValidation ResultsCollector.visit(BeanValidationResultsCollec tor.java:126)
    ... 94 more
    Regards
    linwei

  4. #4
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    You should register a custom PropertyEditor for your rawFile attribute or for all attributes of type File.

    See the User documentation (http://opensource.atlassian.com/conf...ropertyEditors) for info on how to do that.

    Hope this helps,

    Peter

  5. #5
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    crap, stupid markup

    here is the link:
    http://opensource.atlassian.com/conf...ropertyEditors

  6. #6
    Join Date
    Oct 2004
    Location
    Vancouver, Canada
    Posts
    35

    Default

    Thanks a lot, it works:
    Code:
    <bean id="propertyEditorRegistry" 
    class="org.springframework.richclient.application.support.DefaultPropertyEditorRegistry"> 
        <property name="propertyEditors"> 
            <list> 
               <props> 
                 <prop key="objectClass">int</prop> 
                 <prop key="propertyEditorClass">com.sjv.support.propertyeditors.DefaultIntEditor</prop> 
              </props> 
              <props> 
                 <prop key="objectClass">java.io.File</prop> 
                 <prop key="propertyEditorClass">org.springframework.beans.propertyeditors.FileEditor</prop> 
            </props> 
         </list> 
    </property> 
    </bean>
    Want to confirm: if I want to use some Constraint to validate a property, I must always rigister this property in "propertyEditorRegistry", is it a rule always true?

    And just curious, for my "rawFile", if I don't add the "FileChecks.FileExists()" constraint, it works well to combine the TextField to the "rawFile", a "File" type. So, I think it seems this issue is not for "binding" a value, but only for "validating" a value... Is it possible that the validation use the same method as "binding" to "autowire" the propertyEditor?
    Regards
    linwei

  7. #7
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    Want to confirm: if I want to use some Constraint to validate a property, I must always rigister this property in "propertyEditorRegistry", is it a rule always true?
    No, you only have to register a propertyeditor for "non-default" property types (default property types are String, int, float, ...). For Date's, File's, ... you have to register a property editor. The property editor takes care of the conversion of the userinput to the type and from the type to a string for edit.
    This propertyeditor is also being used for validation.



    Currently there's not much support for property editor bindings, but this issue will be tackled in the near future (I hope...). I think the list of "default" types will be enhanced (to include dates, ...)


    Peter

Similar Threads

  1. Replies: 5
    Last Post: Mar 17th, 2010, 04:32 AM
  2. Replies: 19
    Last Post: Sep 10th, 2007, 12:46 PM
  3. Saving large files to a db using hibernate?
    By Dan Washusen in forum Data
    Replies: 10
    Last Post: Sep 20th, 2006, 12:18 PM
  4. Replies: 2
    Last Post: Aug 27th, 2005, 08:51 AM
  5. Replies: 2
    Last Post: May 2nd, 2005, 05:33 AM

Posting Permissions

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