添加对WicketStuff Spinner属性的fucntion调用

时间:2016-02-15 11:54:56

标签: java properties spinner wicket-1.5 wicketstuff

如何对java.util.Properties'onDecrement进行函数调用, WicketStuff的Spinner配置方法的afterUpdateonStopTextField<String> textField = new TextField<String>("textField ", new Model<String>("0")); textField.add(new Spinner() { @Override protected void configure(Properties p) { super.configure(p); p.put("afterUpdate", "foo()"); } }); void fun() { System.out.println("Hello world!"); } 属性?我尝试了以下但是没有调用该函数:

/*
 * Add a nonenumerable extend() method to Object.prototype.
 * This method extends the object on which it is called by copying properties
 * from the object passed as its argument.  All property attributes are
 * copied, not just the property value.  All own properties (even non-
 * enumerable ones) of the argument object are copied unless a property
 * with the same name already exists in the target object.
 */
Object.defineProperty(Object.prototype,
    "extend",                  // Define Object.prototype.extend
    {
        writable: true,
        enumerable: false,     // Make it nonenumerable
        configurable: true,
        value: function(o) {   // Its value is this function
            // Get all own props, even nonenumerable ones
            var names = Object.getOwnPropertyNames(o);
            // Loop through them
            for(var i = 0; i < names.length; i++) {
                // Skip props already in this object
                if (names[i] in this) continue;
                // Get property description from o
                var desc = Object.getOwnPropertyDescriptor(o,names[i]);
                // Use it to create property on this
                Object.defineProperty(this, names[i], desc);
            }
        }
    });


var mainObject = {name:'test'};
var clone = {};
clone.extend(mainObject);

这些属性的Javadoc是:

  

onIncrement增量后调用的函数
  onDecrement函数   递减后打电话   afterUpdate更新后调用函数   的价值
  onStop调用click或mouseup的函数   (缺省值=假)

请注意,设置其他属性时一切正常。

1 个答案:

答案 0 :(得分:1)

关注https://github.com/wicketstuff/core/blob/034ab2b1363d1f81609fec8362d8a80beb163227/minis-parent/minis/src/main/java/org/wicketstuff/minis/behavior/spinner/Spinner.java#L164-L192我不知道这是如何运作的。 它迭代属性中的值并检查其类型。 else 子句应涵盖您的情况。但问题是java.util.Properties只能包含String键和值,所以它总是会出现在 if 子句中,永远不会出现在 else if 和<强>否则

此代码需要一些改进! 随意创建一个问题并发送一个Pull Request!