0

我有一些用于指定实体列表的 DDC。3 个 DDC 相互更新以缩小结果集。

那工作正常。

第 3 个 DDC 在其表单中调用一个方法,该方法将填充一个 ListView。然后在另一个 Panel 中使用此 ListView 来呈现结果。

该列表已填充并正常工作。

现在我有另一个面板 - 仅用于向此列表添加新条目。我有 BusinessLogic 方法,它创建一个新的空实体并将其传递给面板。那是一次工作 - 该方法在页面的创建时间被调用。

我将 2 个面板添加到 WebMarkupContainer 并为其添加了 updateBehavior。ListView 得到更新,其他 Panel 没有。我的错误在哪里?

public HomePage() {
    AuswahlForm auswahlForm = new AuswahlForm("auswahlForm");
    add(auswahlForm);

    WebMarkupContainer parameterMC = new WebMarkupContainer("parameterMC");
    add(parameterMC);
    parameterMC.setOutputMarkupId(true);
    Panel neuesParameterPanel = new NeuesParameterPanel(
            "neuesParameterPanel", new Model<Dsdefaultparams>(
                    auswahlForm.getNeueParameterSpalte()));

    ParameterListenPanel parameterListenPanel = new ParameterListenPanel(
            "parameterListenPanel", auswahlForm.erstelleParameterListe());

    parameterMC.add(neuesParameterPanel);
    parameterMC.add(parameterListenPanel);

    addAjaxUpdateBehaviorFuerFormKomponenten(
            auswahlForm.getValidierungsAuswahlDropDown(), parameterMC);

}

private void addAjaxUpdateBehaviorFuerFormKomponenten(
        final WebMarkupContainer pSender,
        final WebMarkupContainer... pHinzugefuegteKomponente) {
    pSender.add(new AjaxFormComponentUpdatingBehavior("onchange") {

        private static final long serialVersionUID = 1204890108507070216L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            for (WebMarkupContainer webMarkupContainer : pHinzugefuegteKomponente) {
                target.add(webMarkupContainer);
            }

        }
    });
}

主页包含组件

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import de.bayern.lfl.ama.db.entity.Dsdefaultparams;
import de.bayern.lfl.ama.db.entity.Dsstat;
import de.bayern.lfl.ama.db.entity.Dsstyp;
import de.bayern.lfl.ama.db.entity.Dsvalidierung;
import de.bayern.lfl.ama.gui.controller.helper.AjaxHelper;
import de.bayern.lfl.ama.gui.logik.StationsService;

public class AuswahlForm extends Form<Dsvalidierung> {

    private static final long serialVersionUID = 2976955367939043422L;

    private Dsstat gewaehlteStation;

    private Dsstyp gewaehlterSensor;

    private Dsvalidierung gewaehlteValidierung;

    private List<Dsdefaultparams> gefundeneParams = new ArrayList<Dsdefaultparams>();

    private DropDownChoice<Dsstat> stationsAuswahlDropDown;

    private DropDownChoice<Dsstyp> sensorAuswahlDropDown;

    private DropDownChoice<Dsvalidierung> validierungsAuswahlDropDown;

    @SpringBean
    private StationsService stationsService;

    public AuswahlForm(String pId) {
        super(pId);
        erzeugeAuswahlMenu();

    }

    private void erzeugeAuswahlMenu() {
        stationsAuswahlDropDown = erzeugeStationsAuswahlDropDown();
        sensorAuswahlDropDown = erzeugeSensorAuswahlDropDown();
        validierungsAuswahlDropDown = erzeugeValidierungsDropDown();
        add(sensorAuswahlDropDown);
        add(stationsAuswahlDropDown);
        add(validierungsAuswahlDropDown);

        AjaxHelper.addAjaxUpdateBehaviorFuerFormKomponenten(
                stationsAuswahlDropDown, sensorAuswahlDropDown);
        AjaxHelper.addAjaxUpdateBehaviorFuerFormKomponenten(
                sensorAuswahlDropDown, validierungsAuswahlDropDown);

    }

    public Dsdefaultparams getNeueParameterSpalte() {

        return stationsService.getNeueParameterSpalte(getGewaehlterSensor(),
                getGewaehlteValidierung());

    }

    public ListView<Dsdefaultparams> erstelleParameterListe() {
        LoadableDetachableModel<List<Dsdefaultparams>> model = new LoadableDetachableModel<List<Dsdefaultparams>>() {

            private static final long serialVersionUID = 5616093668912903208L;

            @Override
            protected List<Dsdefaultparams> load() {
                return stationsService
                        .getDsdefaultParamsZuSensorUndValidierung(
                                getGewaehlterSensor(),
                                getGewaehlteValidierung());
            };
        };
        ListView<Dsdefaultparams> parameterListe = new ListView<Dsdefaultparams>(
                "parameterListe", model) {

            private static final long serialVersionUID = -5657161783150179067L;

            @Override
            protected void populateItem(ListItem<Dsdefaultparams> item) {
                item.add(new TextField<String>("wert", Model.of(item
                        .getModelObject().getWert().toString())));
                item.add(new TextField<String>("spalte", Model.of(item
                        .getModelObject().getSpalte().toString())));
            }
        };
        parameterListe.setOutputMarkupId(true);
        return parameterListe;
    }

    protected void ladeWerteUndBefuelleUnterForms() {
        setGefundeneParams(stationsService
                .getDsdefaultParamsZuSensorUndValidierung(
                        getGewaehlterSensor(), getGewaehlteValidierung()));

    }

    private DropDownChoice<Dsstat> erzeugeStationsAuswahlDropDown() {
        final DropDownChoice<Dsstat> stationsAuswahlDropDown = new DropDownChoice<Dsstat>(
                "stationen",
                new PropertyModel<Dsstat>(this, "gewaehlteStation"),
                stationsService.getAlleStationen(),
                new StationsChoiceRenderer());
        return stationsAuswahlDropDown;
    }

    private DropDownChoice<Dsstyp> erzeugeSensorAuswahlDropDown() {
        final DropDownChoice<Dsstyp> sensorAuswahlDropDown = new DropDownChoice<Dsstyp>(
                "sensoren",
                new PropertyModel<Dsstyp>(this, "gewaehlterSensor"),
                getDsstypAuswahl(), new SensorChoiceRenderer());
        sensorAuswahlDropDown.setOutputMarkupId(true);
        return sensorAuswahlDropDown;
    }

    private DropDownChoice<Dsvalidierung> erzeugeValidierungsDropDown() {
        final DropDownChoice<Dsvalidierung> validierungsAuswahlDropDown = new DropDownChoice<Dsvalidierung>(
                "validierungen", new PropertyModel<Dsvalidierung>(this,
                        "gewaehlteValidierung"), getDsvalidierungAuswahl(),
                new DsvalidierungChoiceRenderer());
        validierungsAuswahlDropDown.setOutputMarkupId(true);
        return validierungsAuswahlDropDown;
    }

    private IModel<List<? extends Dsvalidierung>> getDsvalidierungAuswahl() {
        IModel<List<? extends Dsvalidierung>> modelChoices = new AbstractReadOnlyModel<List<? extends Dsvalidierung>>() {

            private static final long serialVersionUID = 6566217311955024230L;

            @Override
            public List<Dsvalidierung> getObject() {
                List<Dsvalidierung> models = stationsService
                        .getAlleValidierungen(getGewaehlterSensor(),
                                getGewaehlteStation());
                if (models == null) {
                    models = Collections.emptyList();
                }
                return models;
            }

        };
        return modelChoices;
    }

    private IModel<List<? extends Dsstyp>> getDsstypAuswahl() {
        IModel<List<? extends Dsstyp>> modelChoices = new AbstractReadOnlyModel<List<? extends Dsstyp>>() {

            private static final long serialVersionUID = 6566217311955024230L;

            @Override
            public List<Dsstyp> getObject() {
                List<Dsstyp> models = stationsService
                        .getAlleSensoren(getGewaehlteStation());
                if (models == null) {
                    models = Collections.emptyList();
                }
                return models;
            }

        };
        return modelChoices;
    }

    public Dsstat getGewaehlteStation() {
        return gewaehlteStation;
    }

    public void setGewaehlteStation(Dsstat pGewaehlteStation) {
        gewaehlteStation = pGewaehlteStation;
    }

    public Dsstyp getGewaehlterSensor() {
        return gewaehlterSensor;
    }

    public void setGewaehlterSensor(Dsstyp pGewaehlterSensor) {
        gewaehlterSensor = pGewaehlterSensor;
    }

    public Dsvalidierung getGewaehlteValidierung() {
        return gewaehlteValidierung;
    }

    public void setGewaehlteValidierung(Dsvalidierung pGewaehlteValidierung) {
        gewaehlteValidierung = pGewaehlteValidierung;
    }

    public List<Dsdefaultparams> getGefundeneParams() {
        return gefundeneParams;
    }

    public void setGefundeneParams(List<Dsdefaultparams> pGefundeneParams) {
        gefundeneParams = pGefundeneParams;
    }

    public DropDownChoice<Dsstat> getStationsAuswahlDropDown() {
        return stationsAuswahlDropDown;
    }

    public void setStationsAuswahlDropDown(
            DropDownChoice<Dsstat> pStationsAuswahlDropDown) {
        stationsAuswahlDropDown = pStationsAuswahlDropDown;
    }

    public DropDownChoice<Dsstyp> getSensorAuswahlDropDown() {
        return sensorAuswahlDropDown;
    }

    public void setSensorAuswahlDropDown(
            DropDownChoice<Dsstyp> pSensorAuswahlDropDown) {
        sensorAuswahlDropDown = pSensorAuswahlDropDown;
    }

    public DropDownChoice<Dsvalidierung> getValidierungsAuswahlDropDown() {
        return validierungsAuswahlDropDown;
    }

    public void setValidierungsAuswahlDropDown(
            DropDownChoice<Dsvalidierung> pValidierungsAuswahlDropDown) {
        validierungsAuswahlDropDown = pValidierungsAuswahlDropDown;
    }

}

参数面板不起作用:

public class NeuesParameterPanel extends Panel {

/**
 * 
 */
private static final long serialVersionUID = 7128594202920579812L;

public NeuesParameterPanel(String pId) {
    super(pId);

}

public NeuesParameterPanel(String pId, IModel<Dsdefaultparams> params) {
    this(pId);

    IModel<Dsdefaultparams> compound = new CompoundPropertyModel<Dsdefaultparams>(
            params);

    Form<Dsdefaultparams> neueParameterForm = new Form<Dsdefaultparams>(
            "neueParameterForm", compound);

    neueParameterForm.add(new TextField<String>("spalte"));
    neueParameterForm.add(new TextField<String>("wert"));

    add(neueParameterForm);
    setOutputMarkupId(true);
}

}

ParameterListPanel 确实...

public class ParameterListenPanel extends Panel {

private static final long serialVersionUID = -315164811829481112L;

private ListView<Dsdefaultparams> parameterListe;

public ParameterListenPanel(String pId) {
    super(pId);
    setOutputMarkupId(true);

}

public ParameterListenPanel(String pId,
        ListView<Dsdefaultparams> pErstelleParameterListe) {
    this(pId);
    ListView<Dsdefaultparams> parameterListe = pErstelleParameterListe;
    Form<Dsdefaultparams> parameterListenForm = new Form<Dsdefaultparams>(
            "parameterListenForm");

    add(parameterListenForm);
    parameterListenForm.add(parameterListe);

    setOutputMarkupId(true);
}

public ListView<Dsdefaultparams> getParameterListe() {
    return parameterListe;
}

public void setParameterListe(ListView<Dsdefaultparams> pParameterListe) {
    parameterListe = pParameterListe;
}

}

4

1 回答 1

0

如果它可能有帮助,请尝试在更新时删除 neuesParameterPanel

移除(neuesParameterPanel);neuesParameterPanel = new NeuesParameterPanel("neuesParameterPanel", new Model(auswahlForm.getNeueParameterSpalte())); neuesParameterPanel.setOutputMarkupId(true); 参数MC.add(neuesParameterPanel);

于 2013-04-09T16:36:34.280 回答