Hello,
 
I wrote my own date editor class, and cannot figure out why it is not being used by WebWork.  (Assume I need a custom date editor.)  I can successfully register it with PropertyEditorManager, and verify that it is registered when my action goes to save an object with dates, but I'm not seeing the behavior I expect nor the print statements I put in my editor class for debugging (thinking of course that it was a problem with my editor...)
 
I registered my date editor, DateTimeEditor, using PropertyManager.registerEditor() for java.util.Date from a static initializer in the base class of my action class, which extends ActionSupport and implements CommandDriven:
 
static
{
   System.out.println("~~~~~~~~~~~Registering Date/Money Editors~~~~~~~~~~~~~~");
   BeanUtil.getPropertyEditor(Date.class);
   PropertyEditorManager.registerEditor(Date.class, DateTimeEditor.class);
   PropertyEditorManager.registerEditor(Date[].class, DateTimeEditor.class);
   PropertyEditorManager.registerEditor(Money.class, MoneyEditor.class);
   PropertyEditorManager.registerEditor(Money[].class, MoneyEditor.class);
   PropertyEditorManager.registerEditor(Percentage.class, PercentageEditor.class);
   PropertyEditorManager.registerEditor(Percentage[].class, PercentageEditor.class);
}
The call to webwork.util.BeanUtil.getPropertyEditor() forces BeanUtil to load and ensures that DateTimeEditor will overwrite webwork.util.editor.DateEditor.  Otherwise, BeanUtil is not loaded until it is used, after DateTimeEditor was registered, and BeanUtil's static intializer replaces DateTimeEditor with webwork.util.editor.DateEditor.
 
Print statements in the save method/command of my action class confirm that my date editor is registered with PropertyEditorManager for dates.  I also tried registering my date editor with PropertyEditorManager using java.sql.Date, just for the hell of it, knowing that it is possible that a date displayed on a page may actually be an instance of java.sql.Date; no dice.  BTW, the editors I wrote for Money and Percentage register fine and get invoked correctly through the framework.  I bet the fact that I wrote those classes means there is no way there is any kind of default property editor around to mess things up.
 
Interestingly, if I ask the property descriptor associated with a date for its editor class, e.g.,
 
      new PropertyDescriptor("startDate", TimeInterval.class).getEditorClass(),
 
where TimeInterval is a class containing startDate, declared as java.util.Date, I get null.  Before you go "ah-HA", note that I also get the same result when I ask for the property descriptor for a property of class Money or Percentage, whose custom editors work fine.  I have to conclude that this is not relevant, but I could be wrong.
 
My objects are all populated with the following code:
 
protected void populate(Object o) throws ResultException
{
   Map parameters = ActionContext.getContext().getParameters();
   for (Iterator keys = parameters.keySet().iterator(); keys.hasNext();)
   {
      String key = (String)keys.next();
 
      try
      {
         BeanUtil.setProperty(key, parameters.get(key), o);
      }
      catch (IllegalArgumentException e)
      {
         e.printStackTrace();
         addError(key, e.getMessage());
      }
   }
 
   if (invalidInput())
      throw new ResultException(INPUT);
}
 
Any ideas?
 
Jed Prentice
 

Reply via email to