Custom FormFieldFactory Problem


EDITED TO SIMPLIFY PROBLEM DESCRIPTION: Previous entry replaced with what was a comment.

Hi,
The problem I am having is I have an AbstractFormFieldFactory helper class, which simplifies the creation of FormFieldFactory instances. However, it does not work. Where the values should be displayed, I only get a blank form with a read-only TtextField.

Whereas, if I return the Field directly (via return new XXX…) then it all works.

Any suggestions as to what I could be doing wrong would be much appreciated.

 public Field createField(Item item, Object propertyId, Component uiContext)
      {
      
      if (! initCalled)
         {
         if (null == contents)
            contents = new HashMap<String, Field>() ;

         contents.put("fullName", new MaskedTextField("Full Name"));
         
         Select selectRole = new Select("Job Title");
         selectRole.addItem("Chief Executive Officer");
         selectRole.setNewItemsAllowed(true);

         contents.put("roleName", selectRole) ;
         
         Select selectGender = new Select("Gender");
         selectGender.addItem("Male");
         selectGender.addItem("Female");
         selectGender.setNewItemsAllowed(false);

         contents.put("gender", selectGender) ;

         Select selectDoc = new Select("ID Document");
         selectDoc.addItem("I/C");
         selectDoc.addItem("Passport");
         selectDoc.addItem("Driving License");
         selectDoc.setNewItemsAllowed(true);
         contents.put("idDocument", selectDoc) ;

         contents.put("idNumber", new MaskedTextField("Document #"));
         contents.put("stockHolding", new MaskedTextField("Stock Holding", "########"));

         Select select = new Select("Nationality");
         select.addItem("Singaporean");
         select.addItem("Malaysian");
         select.addItem("Other");
         select.setNewItemsAllowed(true);         
         contents.put("nationality", select) ;

         contents.put("appointed", new MaskedTextField("Appointed"));
         contents.put("mobleNo", new MaskedTextField("Mobile #"));
         contents.put("eMail", new MaskedTextField("e-Mail"));
         contents.put("remarks", new MaskedTextField("Remarks"));

         initCalled = true ;
         }

      return contents.get((String) propertyId);
      }

Regards,
Anthony

Any suggestions anyone? I am sorry if I am asking a stupid question, but if I am please, point me to the right place in the forums or Book of Vaadin please.
Thanks in advance.

Some more information- I’ve looked at the DefaultFormFactory code and each object returned by the internal method, is in the form of
return new XXX() ;
in my code, I am passing a Class name, e.g.
com.vaadin.ui.Select.class
, for example, and using the Java
newInstance()
method to create a new instance of the class and then return that.

This s what the form factory appears to be objecting to. It seems that ONLY a direct return of a new object works. In my opinion, this is a bug.

I’ve been working on this for over 5 days straight now, and I think I’ve tried every conceivable variation.

If someone has a form factory working that does something similar to what I intended, please let me know, so I can at least see some light at the end of the tunnel and fix my idea, which I am more than happy to post as an addon, once it’s working.

The whole idea of my approach was to be able to “load” the form factory with something like a template to create instances of particular bean methods, with very simple calls such as:

      addField ("fullName", "Full Name") ;
      addField ("shareholder", new CheckBox ("Shareholder")) ;
      addField ("nonExecutive", "Non-Executive Director", CheckBox.class) ;
      addField ("independent", "Independent Director", CheckBox.class) ;
      addField ("votingStock", "Has Voting Stock", CheckBox.class) ;
      addField ("roleName", true) ;
      addField ("gender", true) ;
      addField ("idDocument", true) ;
      addField ("idNumber", "Document #") ;
      addField ("stockHolding", "Stock Holding", "########") ;

The “#######” business is a format statement for the excellent MaskedTextField which in my opinion, should be part of Vaadin’s core.

The idea was to dramatically reduce the amount of code needed for the form to be created, since in my application, I use forms extensivey.

I know that I can use addons like FormBinder addon (which is excellent), but I don’t want to hand code each form. All I wanted to do was have a much simpler way of creating standard forms.

Forgive the frustration in this post, but other than a bug, I really can’t see what the problem might be.

After lots of digging, I found that the problem was the MaskedTextField, it was the only thing I had not changed, as soon as I changed that default return type to TextField, the code worked fine.

Will log a bug with MarkedTextField.