Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wicket儿童面板刷新_Wicket_Panel_Partial Page Refresh - Fatal编程技术网

Wicket儿童面板刷新

Wicket儿童面板刷新,wicket,panel,partial-page-refresh,Wicket,Panel,Partial Page Refresh,我只是想寻找一双额外的眼睛来发现为什么儿童面板在单选按钮选择/更改时不显示/更改可见性,这需要他们刷新 public class OptionsPanel extends Panel { private AutoCompleteSearchField departureField; private HiddenField departureCodeField; private CompoundPropertyModel model; private RadioG

我只是想寻找一双额外的眼睛来发现为什么儿童面板在单选按钮选择/更改时不显示/更改可见性,这需要他们刷新


public class OptionsPanel extends Panel {
    private AutoCompleteSearchField departureField;
    private HiddenField departureCodeField;
    private CompoundPropertyModel model;
    private RadioGroup flightChoices;
    private RadioGroup dateChoices;
    private final TripSearchModel tripSearchModel;
    private WebMarkupContainer optionsContainer;
    private FlexibleDates flexibleDates;
    private FixedDates fixedDates;
    private PassengersAndClass passengersAndClass;
    private static List FIX_CONTAINER_VISIBLE = Lists.newArrayList(true, false, true);
    private static List FLEX_CONTAINER_VISIBLE = Lists.newArrayList(false, true, true);
    private static List HIDE_CONTAINERS = Lists.newArrayList(false, false, false);

    public OptionsPanel(String id, CompoundPropertyModel model) {
        super(id);
        this.model = model;
        this.tripSearchModel = (TripSearchModel) model.getObject();

        add(departureLabel());
        add(departureField());
        add(departureCodeField());

        add(flightType());
        add(travellingWhen());
        add(dateType());

        add(optionsContainer(HIDE_CONTAINERS));
    }

    private Component departureLabel() {
        return new WebMarkupContainer("departureLabel").setOutputMarkupId(true);
    }

    private AutoCompleteSearchField departureField() {
        departureField = new AutoCompleteSearchField("departureField", "From", "flightFromField", null, true, model.bind("departure"));
        departureField.setOutputMarkupId(true);
        departureField.add(new CityValidator(this, departureCodeField));
        return departureField;
    }

    private HiddenField departureCodeField() {
        departureCodeField = new HiddenField("departureCodeField", model.bind("departureCode"));
        departureCodeField.setMarkupId("departureFieldCode");
        return departureCodeField;
    }

    private Component flightType(){
        flightChoices = new RadioGroup("flightTypes");
        flightChoices.setModel(model.bind("tripType"));
        flightChoices.add(listOfRadio(flightsTypeList(), "flightType"));
        return flightChoices;
    }

    private List flightsTypeList() {
        return Arrays.asList(
                new RadioOptionObject("one way", new Model(TRIP_TYPE_ONE_WAY)),
                new RadioOptionObject("return", new Model(TRIP_TYPE_RETURN))
        );
    }

    private Component travellingWhen(){
        return new Label("travellingWhen", new StringResourceModel("travelling_when", this, new Model("")).getString());
    }

    private Component dateType(){
        dateChoices = new RadioGroup("dateTypes");
        dateChoices.setModel(model.bind("dateType"));
        dateChoices.add(listOfRadio(datesTypeList(), "dateType"));
        return dateChoices;
    }

    private List datesTypeList() {
        return Arrays.asList(
                new RadioOptionObject("Flexible dates", new Model(DATE_TYPE_FLEX)),
                new RadioOptionObject("Fixed dates", new Model(DATE_TYPE_FIX)));
    }

    private ListView listOfRadio(final List flightDateOptionValues, final String componentId) {
        ListView listView = new ListView(componentId + "sList", flightDateOptionValues) {
            @Override
            protected void populateItem(final ListItem listItem) {
                final Radio radio = new Radio(componentId + "Radio", ((RadioOptionObject) listItem.getModelObject()).getRadioModel()) {
                    @Override
                    public String getValue() {
                        return listItem.getDefaultModelObjectAsString();
                    }

                    @Override
                    protected boolean getStatelessHint() {
                        return true;
                    }
                };
                radio.add(new AjaxEventBehavior("onchange") {
                    @Override
                    protected void onEvent(AjaxRequestTarget target) {
                        tripSearchModel.setDateType(radio.getModelObject().toString());
                        refreshPanel(target);
                    }
                });
                listItem.add(radio);
                listItem.add(new Label(componentId + "Name", new StringResourceModel(radio.getModelObject().toString(), this, radio.getModel())));
            }
        };
        return listView;
    }

    private void refreshPanel(AjaxRequestTarget target) {
        this.remove(optionsContainer);
        target.addComponent(optionsContainer(visibility()));
    }

    private List visibility() {
        return visibilityMode(((TripSearchModel) model.getObject()).getDateType());
    }

    private Component optionsContainer(List visibility){
        optionsContainer = new WebMarkupContainer("optionsContainer");
        optionsContainer.add(flexibleDates(visibility.get(0)));
        optionsContainer.add(fixedDates(visibility.get(1)));
        optionsContainer.add(passengersAndClass(visibility.get(2)));
        optionsContainer.setOutputMarkupId(true);
        optionsContainer.setVisible(true);
        return optionsContainer;
    }

    private Component flexibleDates(Boolean visibility){
        flexibleDates = new FlexibleDates("flexibleDates", model);
        flexibleDates.setOutputMarkupId(true);
        flexibleDates.setVisible(visibility);
        return flexibleDates;
    }

    private Component fixedDates(Boolean visibility){
        fixedDates = new FixedDates("fixedDates", model);
        fixedDates.setOutputMarkupId(true);
        fixedDates.setVisible(visibility);
        return fixedDates;
    }

    private Component passengersAndClass(Boolean visibility){
        passengersAndClass = new PassengersAndClass("passengersAndClass", model);
        passengersAndClass.setOutputMarkupId(true);
        passengersAndClass.setVisible(visibility);
        return passengersAndClass;
    }

    private List visibilityMode(String dateType) {
        if(DATE_TYPE_FIX.equalsIgnoreCase(dateType)){
            return FIX_CONTAINER_VISIBLE;
        } else if(DATE_TYPE_FLEX.equalsIgnoreCase(dateType)){
            return FLEX_CONTAINER_VISIBLE;
        } else{
            return HIDE_CONTAINERS;
        }
    }
}

我认为您可能会遇到的一个潜在问题是,您监听ajaxonchange事件,并试图根据假定已更改的模型对面板进行更改。根据我对radio类型表单组件的经验,您可能需要使用
AjaxFormComponentUpdateingBehavior
(而不是
AjaxEventBehavior
)来捕获对此类表单组件模型的更改。希望这有帮助


编辑:与其列出警告(您需要对某些表单组件使用另一种类型的行为),我只需添加一个指向文档的链接:

在一天结束时,我发现为我隐藏了另一个复活节彩蛋

radio.add(new AjaxEventBehavior("onchange") {
                    @Override
                    protected void onEvent(AjaxRequestTarget target) {
                        tripSearchModel.setDateType(radio.getModelObject().toString());
                        refreshPanel(target);
                    }

我在两个不同的无线电组的事件中更改了相同的日期参数,这使得表单变得无用。这是一个变化,第二个变化是从WebMarkupContainer移动到EnclosureContainer,建议在Wicket邮件列表上使用它来更改组件的可见性状态。尽管如此,我还是会尝试使用AjaxFormComponentUpdateingBehavior thank you@Martin Peters

从容器中移除独生子面板,将其添加回来并刷新独生子容器,从而解决了主要问题。但是我需要更多的测试