标签: propertyeditor

如何为特定类型的所有实例实现自己的自定义属性编辑器?

我已经按照一些关于创建自定义属性编辑器对话框的教程,但涉及的内容很多,我无法正常工作.我想要完成的是一个自定义表单,带有日期选择器(日历),时间选择器,以及确定和取消按钮.表单完全没问题,但是我如何实现这一点,以便我可以使用按钮发布属性编辑器的某个类型的任何组件中的属性?

我想完全覆盖TDateTime类型并将我的自定义编辑器放在其位置,因此无论在何处TDateTime发布并在Object Inspector中可见,我都可以使用此编辑器在同一窗口中同时修改日期和时间.

问题是关于创建自定义属性编辑器的文档很差,尽管有些资源非常透彻,但它们会详细介绍这些功能,并且在最常见的场景中缺乏重点.

ide delphi propertyeditor custom-component delphi-xe2

10
推荐指数
1
解决办法
5424
查看次数

Spring MVC:将3个下拉列表绑定到SimpleFormController中的日期属性

我应该如何配置类以将三个下拉列表(日期,月份,年份)绑定到单个Date属性,以使其按照"每个属性的单个请求参数"方案的工作方式工作?我想应该通过重写initBinder方法添加一些自定义PropertyEditors.还有什么 ?

java spring-mvc propertyeditor

6
推荐指数
1
解决办法
5932
查看次数

如何使Object Inspector显示更多TColor属性值?

IDE Object Inspector使用下拉ColorBox显示TColor属性,颜色可以通过名称选择 - clBlack等,如图形单元中所定义.问题是在图形单元中定义的clWeb颜色不存在,我定义的任何自定义颜色也不存在.

那么如何扩展Object Inspector中可选择的已定义颜色?

PS Delphi XE

delphi components propertyeditor delphi-xe

6
推荐指数
1
解决办法
1857
查看次数

是否有基于注释的方法在Spring MVC 3.0中全局注册PropertyEditors?

我想知道是否有一种方法可以在Spring MVC 3.0之内全局注册PropertyEditor.在他们的文档文档中,他们展示了如何使用注释来基于每个控制器自定义bean PropertyEditor,并且 - 在我看来 - 就像我在全球范围内这样做的XML方式.所以我想知道,有没有办法,只需使用注释为所有控制器注册PropertyEditors,而无需为每个控制器执行@InitBinder方法.使用@InitBinder方法创建公共超类也是不可取的.

其他问题上这个问题被问春3.0发布之前.

annotations spring-mvc propertyeditor javabeans

6
推荐指数
1
解决办法
1874
查看次数

Spring CustomNumberEditor解析不是数字的数字

我正在使用Spring CustomNumberEditor编辑器来绑定我的浮点值,并且我已经尝试过,如果值不是数字,有时它可以解析该值并且不返回任何错误.

  • number = 10 ......那么数字是10,没有错误
  • number = 10a ......那么数字是10并且没有错误
  • number = 10a25 ......然后数字是10,没有错误
  • number = a ......错误,因为该号码无效

所以似乎编辑器会解析它的值,直到它能够并省略其余的值.有没有办法配置这个编辑器所以验证是严格的(所以数字像10a或10a25导致错误)或我是否必须构建我的自定义实现.我在CustomDateEditor/DateFormat中看起来像设置lenient为false,因此无法将日期解析为最可能的日期.

我注册编辑器的方式是:

@InitBinder
public void initBinder(WebDataBinder binder){
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setGroupingUsed(false);
    binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, numberFormat, true));
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

java data-binding spring spring-mvc propertyeditor

5
推荐指数
2
解决办法
4402
查看次数

如何修改TComponentProperty以仅显示下拉列表中的特定项目?

请考虑这样的场景:

我有一个被调用的组件TMenuItemSelector,它有两个已发布的属性:PopupMenu- 允许TPopupMenu从表单中选择一个实例,并MenuItem允许从表单中选择任何实例TMenuItem.

我想以MenuItem一种方式修改属性的属性编辑器,在PopupMenu分配时,只有菜单项PopupMenu才能在下拉列表中看到.

我知道我需要编写自己的后代TComponentProperty和覆盖GetValues方法.问题是我不知道如何访问TMenuItemSelector正在撒谎的表单.

Original TComponentProperty使用此方法迭代所有可用实例:

procedure TComponentProperty.GetValues(Proc: TGetStrProc);
begin
  Designer.GetComponentNames(GetTypeData(GetPropType), Proc);
end;
Run Code Online (Sandbox Code Playgroud)

但是,Designer似乎是预编译的,所以我不知道它是如何GetComponentNames工作的.

这就是我到目前为止所做的,我想我唯一缺少的是实现GetValues:

unit uMenuItemSelector;

interface

uses
  Classes, Menus, DesignIntf, DesignEditors;

type
  TMenuItemSelector = class(TComponent)
  private
    FPopupMenu: TPopUpMenu;
    FMenuItem: TMenuItem;
    procedure SetPopupMenu(const Value: TPopUpMenu);
    procedure SetMenuItem(const Value: TMenuItem);
  published
    property PopupMenu: TPopUpMenu read FPopupMenu write SetPopupMenu; …
Run Code Online (Sandbox Code Playgroud)

delphi propertyeditor delphi-2009

4
推荐指数
1
解决办法
943
查看次数

在 Spring 中使用 setAllowedFields() 方法

我正在使用 Spring 3.2.0。我已经注册了一些自定义属性编辑器以满足一些基本需求,如下所示。

import editors.DateTimeEditor;
import editors.StrictNumberFormatEditor;
import java.math.RoundingMode;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.joda.time.DateTime;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.beans.propertyeditors.URLEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.context.request.WebRequest;

@ControllerAdvice
public final class GlobalDataBinder 
{
    @InitBinder
    public void initBinder(WebDataBinder binder, WebRequest request)
    {
        binder.setIgnoreInvalidFields(true);
        binder.setIgnoreUnknownFields(true);
        //binder.setAllowedFields(someArray);
        NumberFormat numberFormat=DecimalFormat.getInstance();
        numberFormat.setGroupingUsed(false);
        numberFormat.setMaximumFractionDigits(2);
        numberFormat.setRoundingMode(RoundingMode.HALF_UP);

        binder.registerCustomEditor(DateTime.class, new DateTimeEditor("MM/dd/yyyy HH:mm:ss", true));
        binder.registerCustomEditor(Double.class, new StrictNumberFormatEditor(Double.class, numberFormat, true));
        binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
        binder.registerCustomEditor(URL.class, new URLEditor());
    } 
}
Run Code Online (Sandbox Code Playgroud)

到目前为止我已经注册了这么多编辑。其中两个DateTimeEditorStrictNumberFormatEditor通过重写各自的方法进行定制,以满足数字格式和Joda-Time的自定义需求。

由于我使用的是 Spring 3.2.0,因此我可以利用@ControllerAdvice …

spring spring-mvc propertyeditor databinder spring-3

2
推荐指数
1
解决办法
1万
查看次数