2

(はい、いいえ、不明) のような RadioField を作成しようとしています。「はい」の場合、テキストフィールドがあります。テキストフィールドに何か入力すると、ラジオボタンで「はい」が選択されます。私はこれを試しましたが、例外が発生しています:

size = new NumberField<Double>("size", fieldLabel("size"), HasUnits.MICROMETER);

size.add(new AjaxFormComponentUpdatingBehavior("onchange") {

    private static final long serialVersionUID =
        2462233190993745889L;

    @Override
    protected void onUpdate(final AjaxRequestTarget target) {
        downSet.setDefaultModelObject("yes");
    }
});
add(size);
size.setOutputMarkupId(true);

ここに私が得ている例外があります:

org.apache.wicket.WicketRuntimeException: Behavior redb.main.modules.sample.view.details.pck.DownSetPanel$2 can only be added to an instance of a FormComponent
    at org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior.onBind(AjaxFormComponentUpdatingBehavior.java:79) ~[wicket-core-6.8.0.jar:6.8.0]
    at org.apache.wicket.behavior.AbstractAjaxBehavior.bind(AbstractAjaxBehavior.java:68) ~[wicket-core-6.8.0.jar:6.8.0]
    at org.apache.wicket.Behaviors.add(Behaviors.java:59) ~[wicket-core-6.8.0.jar:6.8.0]
    at org.apache.wicket.Component.add(Component.java:4511) ~[wicket-core-6.8.0.jar:6.8.0]
    at redb.main.modules.sample.view.details.pck.DownSetPanel.onInitialize(DownSetPanel.java:61) ~[DownSetPanel.class:na]
    at org.apache.wicket.Component.fireInitialize(Component.java:863) ~[wicket-core-6.8.0.jar:6.8.0]
    at org.apache.wicket.MarkupContainer$3.component(MarkupContainer.java:961) ~[wicket-core-6.8.0.jar:6.8.0]
    at org.apache.wicket.MarkupContainer$3.component(MarkupContainer.java:957) ~[wicket-core-6.8.0.jar:6.8.0]
    at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:144) ~[wicket-util-6.8.0.jar:6.8.0]
    at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:162) ~[wicket-util-6.8.0.jar:6.8.0]
    at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:162) ~[wicket-util-6.8.0.jar:6.8.0]
    at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:162) ~[wicket-util-6.8.0.jar:6.8.0]
    at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:162) ~[wicket-util-6.8.0.jar:6.8.0]
    at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:123) ~[wicket-util-6.8.0.jar:6.8.0]
    at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:192) ~[wicket-util-6.8.0.jar:6.8.0]
    at org.apache.wicket.MarkupContainer.visitChildren(MarkupContainer.java:875) ~[wicket-core-6.8.0.jar:6.8.0] 

そして私のNumberFieldクラス:

public class NumberField<T extends Number & Comparable<T>> extends SampleField implements HasUnits {

    private static final long serialVersionUID = 4885709350741384398L;

    private NumberInput<T> numberInput;
    private String unit;

    public NumberField(String id, IModel<String> fieldLabel, IModel<T> model) {
        super(id, fieldLabel, model);
    }

    public NumberField(String id, IModel<String> fieldLabel) {
        super(id, fieldLabel);
    }

    public NumberField(String id, IModel<String> fieldLabel, String unit) {
        super(id, fieldLabel);
        this.unit = unit;
    }

    @SuppressWarnings("unchecked")
    public void onInitialize() {
        super.onInitialize();
        Form<T> f = new Form<>("form");
        this.numberInput = new NumberInput<T>("value",
            (IModel<T>) getDefaultModel());
        this.numberInput.setUnit(unit);
        f.add(numberInput);
        add(f);
    }

}

SampleFieldクラス:

public abstract class SampleField extends Panel {

    private static final long serialVersionUID = 1L;

    public SampleField(String id, IModel<String> fieldLabel) {
        super(id);
        addFieldName(fieldLabel);
    }

    public SampleField(String id, IModel<String> fieldLabel, IModel<?> model) {
        super(id, new CompoundPropertyModel<>(model));
        addFieldName(fieldLabel);
    }

    private final void addFieldName(IModel<String> fieldLabel) {
        add(new Label("fieldname", fieldLabel));
    }

}

どうすればこれを解決できるか考えている人はいますか?

4

2 に答える 2

1

NumberField で AjaxEventBehavior("change") を試してください。さらに深刻な場合は、ラップされた numberInput に動作を追加する必要があります。

于 2014-05-05T19:34:17.137 に答える