Results 1 to 2 of 2

Thread: Creating a Custom PropertyEditor

  1. #1

    Default Creating a Custom PropertyEditor

    As per a tip from Ollie

    Also a few suggestions:

    * For the special date pickers use a custom PropertyEditor registered for the Date class. That way they get automatically inserted where needed.
    * Let the binding framework create all of your controls rather than doing it yourself. In your initComponents() method you are creating whole lot of components expect for the JFormattedTextFields there's not need. In fact you can even avoid explicitly creating the JFormattedTextFields by registering custom PropertyEditors for the fields that need the special JFormattedTextField formatting.

    HTH

    Ollie
    in this thread http://forum.springframework.org/showthread.php?t=15213 I'm trying to create a custom PropertyEditor. The one for the date picker got way too complex too quickly so I scaled my effords back some. Now the one I'm writeing is a simple JComboBox that uses a class called PaceValidValue as its list object which is nothing more that a name value pair of which when its toString() method is called the value is returned.

    The problem I'm having is that the PropertyEditor I created does not seam to bind to the form model and I can not see why it does not. Here is the code:

    Code:
    /**
     *
     * @author stavares
     */
    public class PaceValidValuePropertyEditor extends PropertyEditorSupport 
            implements ChangeListener, ActionListener
    {
        private JComboBox jComboBox;
        private List theList;    
        
        /** Creates a new instance of PaceValidValuePropertyEditor */
        public PaceValidValuePropertyEditor(List theList)
        {        
            jComboBox = new JComboBox(theList.toArray());        
            jComboBox.addActionListener(this);
        }
        
        public boolean supportsCustomEditor()
        {
            return true;
        }
        
        public Component getCustomEditor()
        {        
            return jComboBox;
        }
        
        public void setValue(Object value)
        {
            PaceValidValue paceValidValue = (PaceValidValue)value;
            jComboBox.setSelectedItem(paceValidValue);        
        }
        
        public Object getValue()
        {
            return jComboBox.getSelectedItem();
        }
            
        public void stateChanged(ChangeEvent e)
        {
            firePropertyChange();
        }
        
        public void actionPerformed(ActionEvent e)
        {
            JComboBox cb = (JComboBox)e.getSource();        
            this.setValue(cb.getSelectedItem());        
        }
    }
    and here is the form that is using the above PropertyEditor

    Code:
    public class CreateOffenderFormPageOffender extends AbstractForm
    {
        public static final String OFFENDER_PAGE = "offenderPage";
        private IdentificationSupport identificationSupport;
        
        /** Creates a new instance of CreateOffenderFormPageOffender */
        public CreateOffenderFormPageOffender(FormModel formModel)
        {
            super(formModel, OFFENDER_PAGE);
        }
        
        protected JComponent createFormControl()
        {
            JComponent[] jcomponent;
            JLabel jlabel;
            JComboBox jcomboBox;
            
            // builder.addSeparator("separator.addressDetails");        
            TableFormBuilder formBuilder = new TableFormBuilder(getFormModel());
            
            registerCustomEditors();
            
            formBuilder.add("iincarcerationNumber");
            formBuilder.add("isrg");
            formBuilder.add("ijobCode","colspan=1");
            formBuilder.row();
            formBuilder.add("iinmateId");
            formBuilder.add("ipinNo");
            formBuilder.add("ibciNumber");
            formBuilder.add("icommConfEligDate");
            formBuilder.row();
            formBuilder.add("ifirstName");
            formBuilder.add("iminit");
            formBuilder.add("ilastName");
            formBuilder.add("isuffix");
            formBuilder.row();
            formBuilder.add("idob","colspan=1");
                    
            jcomponent = formBuilder.add("isexPvv","colspan=1");        
            jcomboBox = (JComboBox)jcomponent[1];
            jcomboBox.setEditable(false);
            
            jcomponent = formBuilder.add("iclassCodePvv","colspan=3");        
            jcomboBox = (JComboBox)jcomponent[1];
            jcomboBox.setEditable(false);        
                    
            return formBuilder.getForm();
        }
        
        private void registerCustomEditors()
        {
            identificationSupport = (IdentificationSupport)this.getFormObject();
            
            getFormModel().registerCustomEditor("isexPvv", 
                        new PaceValidValuePropertyEditor(identificationSupport
                        .getIsexList()));
            
            getFormModel().registerCustomEditor("iclassCodePvv", 
                        new PaceValidValuePropertyEditor(identificationSupport
                        .getIclassCodeList()));
        }
    }
    The reason I belive its not getting binded is I have a validation rule on each of the two fields using the PropertyEditor of requried yet no matter if I selected an Item out of the list of the comboBox the fields' invalid decorator icon remains on the screen.

    So the Question is what am I doing wrong????
    Last edited by robyn; May 16th, 2006 at 04:15 AM.
    -ScottTavares-

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default

    So the Question is what am I doing wrong????
    PropertyEditors registered directly with a form model are only used as simple type converters. If they support custom editors they are ignored....

    Though this is all academic as the new code base does not use custom property editors at all. I suggest you do an update and then have a look at the CustomDatePickerBinder in the pet clinic sample.

    Ollie

Similar Threads

  1. Replies: 4
    Last Post: Oct 5th, 2005, 11:04 AM
  2. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. DefaultAdvisorAutoProxyCreator skipping beans
    By youngm in forum Container
    Replies: 6
    Last Post: Apr 12th, 2005, 04:29 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
  •