This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/main by this push:
     new 39c8874b741 CAUSEWAY-3859: Java record refactoring (part 42)
39c8874b741 is described below

commit 39c8874b74186782883418e6fdad37122445557e
Author: Andi Huber <[email protected]>
AuthorDate: Tue Feb 25 18:52:21 2025 +0100

    CAUSEWAY-3859: Java record refactoring (part 42)
---
 .../choices/AttributePanelWithSelect.java          |   6 +-
 .../choices/ObjectChoicesAttributePanel.java       |   8 +-
 .../choices/ValueChoicesAttributePanel.java        |  12 +--
 .../widgets/select2/ChoiceProviderRecord.java      |   5 +-
 .../ui/components/widgets/select2/MultiChoice.java |  94 +++++++++++++++++
 .../ui/components/widgets/select2/Select2.java     | 114 ++++++---------------
 .../widgets/select2/Select2MultiChoiceExt.java     | 101 ------------------
 .../widgets/select2/Select2OnSelect.java           |  17 +--
 .../{Select2ChoiceExt.java => SingleChoice.java}   |  42 +++-----
 9 files changed, 166 insertions(+), 233 deletions(-)

diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/AttributePanelWithSelect.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/AttributePanelWithSelect.java
index 919041d1372..3255ab28b9b 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/AttributePanelWithSelect.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/AttributePanelWithSelect.java
@@ -58,10 +58,10 @@ protected AttributePanelWithSelect(
     protected final Select2 createSelect2(
             final String id) {
         var attributeModel = attributeModel();
-        var select2 = Select2.createSelect2(id, attributeModel,
+        var select2 = Select2.create(id, attributeModel,
                 new ChoiceProviderRecord(attributeModel),
                 getAttributeModelChangeDispatcher());
-        var settings = select2.getSettings();
+        var settings = select2.settings();
         settings.setPlaceholder(attributeModel.getFriendlyName());
 
         switch(attributeModel.getChoiceProviderSort()) {
@@ -102,7 +102,7 @@ protected final boolean hasAnyChoices() {
     }
 
     public final boolean checkSelect2Required() {
-        return select2.checkRequired();
+        return select2.isRequired();
     }
 
     @Override
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/ObjectChoicesAttributePanel.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/ObjectChoicesAttributePanel.java
index 1512b43248c..385014ff46a 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/ObjectChoicesAttributePanel.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/ObjectChoicesAttributePanel.java
@@ -86,7 +86,7 @@ protected FormComponent<ManagedObject> 
createFormComponent(final String id, fina
 
         this.select2 = createSelect2(ID_AUTO_COMPLETE);
 
-        objectLink.addOrReplace(select2.asComponent());
+        objectLink.addOrReplace(select2.component());
         objectLink.setOutputMarkupId(true);
 
         return objectLink;
@@ -180,7 +180,7 @@ private void syncWithInput() {
         }
 
         // set mutability
-        select2.setEnabled(objectLink.isEnableAllowed()
+        select2.setMutable(objectLink.isEnableAllowed()
                 && !getModel().isViewingMode());
 
         /* XXX not sure if required any more
@@ -242,8 +242,8 @@ void convertInput() {
         if(isEditable()) {
 
             // flush changes to pending model
-            var adapter = select2.getConvertedInputValue();
-            pendingValue.setValue(adapter);
+            var managedObject = select2.convertedInputValue();
+            pendingValue.setValue(managedObject);
         }
 
         objectLink.setConvertedInput(pendingValue.getValue());
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/ValueChoicesAttributePanel.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/ValueChoicesAttributePanel.java
index 6ceb9e06f2a..5215228bbfd 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/ValueChoicesAttributePanel.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/attributes/choices/ValueChoicesAttributePanel.java
@@ -62,7 +62,7 @@ protected FormComponent<ManagedObject> createFormComponent(
             select2.clearInput();
         }
         @SuppressWarnings("rawtypes") // incompatible generic type parameter 
cast
-        FormComponent formComponent = select2.asComponent();
+        FormComponent formComponent = select2.component();
         return formComponent;
     }
 
@@ -78,7 +78,7 @@ protected void onInitializeNotEditable() {
         super.onInitializeNotEditable();
         if(isCompactFormat) return;
         // View: Read only
-        select2.setEnabled(false);
+        select2.setMutable(false);
     }
 
     @Override
@@ -86,7 +86,7 @@ protected void onInitializeEditable() {
         super.onInitializeEditable();
         if(isCompactFormat) return;
         // Edit: read/write
-        select2.setEnabled(true);
+        select2.setMutable(true);
         clearTitleAttribute();
     }
 
@@ -95,7 +95,7 @@ protected void onInitializeReadonly(final String 
disableReason) {
         super.onInitializeReadonly(disableReason);
         if(isCompactFormat) return;
         setTitleAttribute(disableReason);
-        select2.setEnabled(false);
+        select2.setMutable(false);
     }
 
     @Override
@@ -103,7 +103,7 @@ protected void onMakeNotEditable(final String 
disableReason) {
         super.onMakeNotEditable(disableReason);
         if(isCompactFormat) return;
         setTitleAttribute(disableReason);
-        select2.setEnabled(false);
+        select2.setMutable(false);
     }
 
     @Override
@@ -111,7 +111,7 @@ protected void onMakeEditable() {
         super.onMakeEditable();
         if(isCompactFormat) return;
         clearTitleAttribute();
-        select2.setEnabled(true);
+        select2.setMutable(true);
     }
 
     // -- CHOICE TITLE HANDLER
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/ChoiceProviderRecord.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/ChoiceProviderRecord.java
index d29a610319e..367c7b359b3 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/ChoiceProviderRecord.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/ChoiceProviderRecord.java
@@ -69,9 +69,8 @@ public String getDisplayValue(final ObjectMemento 
choiceMemento) {
      * available choices.
      */
     public String getIdValue(final ObjectMemento choiceMemento) {
-        if (choiceMemento == null) {
-            return ObjectMemento.NULL_ID;
-        }
+        if (choiceMemento == null) return ObjectMemento.NULL_ID;
+        
         return ObjectMemento.enstringToUrlBase64(choiceMemento);
     }
 
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/MultiChoice.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/MultiChoice.java
new file mode 100644
index 00000000000..7205c4ab906
--- /dev/null
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/MultiChoice.java
@@ -0,0 +1,94 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.causeway.viewer.wicket.ui.components.widgets.select2;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.wicket.model.IModel;
+import org.wicketstuff.select2.Select2MultiChoice;
+import org.apache.causeway.applib.id.LogicalType;
+import org.apache.causeway.core.metamodel.context.HasMetaModelContext;
+import org.apache.causeway.core.metamodel.object.ManagedObject;
+import org.apache.causeway.core.metamodel.objectmanager.memento.ObjectMemento;
+import org.apache.causeway.viewer.wicket.model.models.UiAttributeWkt;
+
+record MultiChoice(
+    LogicalType logicalType,
+    Select2MultiChoice<ObjectMemento> component)
+implements Select2, HasMetaModelContext {
+
+    MultiChoice(
+            final String id,
+            final IModel<Collection<ObjectMemento>> model,
+            final UiAttributeWkt attributeModel,
+            final ChoiceProviderRecord choiceProvider) {
+        this(
+            attributeModel.getElementType().logicalType(),
+            new Select2MultiChoice<>(id, model, 
choiceProvider.toSelect2ChoiceProvider()) {
+                private static final long serialVersionUID = 1L;
+                private boolean workaround;
+
+                // -- bug in wicket 8.8.0
+                @Override public void updateModel() {
+                    workaround = true;
+                    super.updateModel();
+                    workaround = false;
+                }
+                @Override public Collection<ObjectMemento> getModelObject() {
+                    var modelObj = getModelObject();
+                    if(workaround) {
+                        return modelObj==null
+                                ? null
+                                : new ArrayList<>(modelObj);
+                    }
+                    return modelObj;
+                }
+                // --
+
+            });
+
+        component.getSettings().setCloseOnSelect(true);
+        component.getSettings().setWidth("auto");
+        component.getSettings().setDropdownAutoWidth(true);
+
+        component.setOutputMarkupPlaceholderTag(true);
+    }
+
+    @Override
+    public ManagedObject convertedInputValue() {
+        return getObjectManager().demementify(packedConvertedInput());
+    }
+
+    @Override
+    public ObjectMemento objectMemento() {
+        return packedModelObject();
+    }
+
+    // -- HELPER
+
+    private ObjectMemento packedModelObject() {
+        return ObjectMemento.packed(logicalType, component.getModelObject());
+    }
+
+    private ObjectMemento packedConvertedInput() {
+        return ObjectMemento.packed(logicalType, 
component.getConvertedInput());
+    }
+
+}
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2.java
index 9047ce6d98c..37f9ce9739c 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2.java
@@ -20,123 +20,77 @@
 
 import java.io.Serializable;
 
-import org.apache.wicket.behavior.Behavior;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.LambdaModel;
 import org.apache.wicket.model.Model;
-import org.jspecify.annotations.NonNull;
 import org.wicketstuff.select2.AbstractSelect2Choice;
-import org.wicketstuff.select2.Select2Choice;
-import org.wicketstuff.select2.Select2MultiChoice;
+import org.wicketstuff.select2.Settings;
 
-import org.apache.causeway.commons.functional.Either;
+import org.apache.causeway.commons.internal.base._Casts;
 import org.apache.causeway.core.metamodel.object.ManagedObject;
 import org.apache.causeway.core.metamodel.objectmanager.memento.ObjectMemento;
 import 
org.apache.causeway.viewer.wicket.model.models.AttributeModelWithMultiChoice;
 import 
org.apache.causeway.viewer.wicket.model.models.AttributeModelWithSingleChoice;
-import org.apache.causeway.viewer.wicket.model.models.HasCommonContext;
 import org.apache.causeway.viewer.wicket.model.models.UiAttributeWkt;
 import 
org.apache.causeway.viewer.wicket.ui.components.attributes.AttributeModelChangeDispatcher;
 
-/**
- * Wrapper around either a {@link Select2Choice} or a {@link 
Select2MultiChoice}.
- */
-public record Select2(
-        Either<Select2ChoiceExt, Select2MultiChoiceExt> select2Choice)
-implements
-    Serializable,
-    HasCommonContext {
+public interface Select2 extends Serializable {
 
-    public static Select2 createSelect2(
-            final String id,
-            final UiAttributeWkt attributeModel,
-            final ChoiceProviderRecord choiceProvider,
-            final AttributeModelChangeDispatcher select2ChangeDispatcher) {
-        var select2 = new Select2(attributeModel.isSingular()
-                ? Either.left(
-                        Select2ChoiceExt.create(id,
+    static Select2 create(
+        final String id,
+        final UiAttributeWkt attributeModel,
+        final ChoiceProviderRecord choiceProvider,
+        final AttributeModelChangeDispatcher select2ChangeDispatcher) {
+        var select2 = attributeModel.isSingular()
+                ? new SingleChoice(id,
                                 
AttributeModelWithSingleChoice.chain(attributeModel),
                                 attributeModel,
-                                choiceProvider))
-                : Either.right(
-                        Select2MultiChoiceExt.create(id,
-                                
AttributeModelWithMultiChoice.chain(attributeModel),
+                                choiceProvider)
+                : new MultiChoice(id,
+                                
_Casts.uncheckedCast(AttributeModelWithMultiChoice.chain(attributeModel)),
                                 attributeModel,
-                                choiceProvider)));
+                                choiceProvider);
 
-        select2.setLabel(Model.of(attributeModel.getFriendlyName()));
-        select2.getSettings().setWidth("100%");
+        var component = select2.component();
+        component.setOutputMarkupPlaceholderTag(true);
+        component.getSettings().setCloseOnSelect(true);
+        component.getSettings().setDropdownAutoWidth(true);
+        component.getSettings().setWidth("100%");
+        component.setLabel(Model.of(attributeModel.getFriendlyName()));
 
         // listen on select2:select/unselect events (client-side)
-        select2.add(new Select2OnSelect(attributeModel, 
select2ChangeDispatcher));
+        component.add(new Select2OnSelect(attributeModel, 
select2ChangeDispatcher));
 
         return select2;
     }
 
-    // canonical constructor
-    public Select2(final @NonNull Either<Select2ChoiceExt, 
Select2MultiChoiceExt> select2Choice) {
-        this.select2Choice = select2Choice;
-        asComponent().setOutputMarkupId(true);
-    }
-
-    public org.wicketstuff.select2.Settings getSettings() {
-        return select2Choice.fold(
-                Select2ChoiceExt::getSettings,
-                Select2MultiChoiceExt::getSettings);
-    }
-
-    public AbstractSelect2Choice<ObjectMemento, ?> asComponent() {
-        return select2Choice.fold(
-                single->single,
-                multi->multi);
-    }
-
-    public void clearInput() {
-        asComponent().clearInput();
-    }
+    AbstractSelect2Choice<ObjectMemento, ?> component();
+    ManagedObject convertedInputValue();
+    ObjectMemento objectMemento();
 
-    public void setEnabled(final boolean mutability) {
-        asComponent().setEnabled(mutability);
-    }
-
-    public boolean checkRequired() {
-        return asComponent().checkRequired();
-    }
-
-    public ManagedObject getConvertedInputValue() {
-        return getObjectManager().demementify(convertedInput());
-    }
-
-    public IModel<String> obtainOutputFormatModel() {
+    default IModel<String> obtainOutputFormatModel() {
         return LambdaModel.<String>of(()->{
-            var memento = memento();
+            var memento = objectMemento();
             return memento!=null
                     ? memento.title()
                     : null;
         });
     }
 
-    // -- HELPER
-
-    private void setLabel(final Model<String> model) {
-        asComponent().setLabel(model);
+    default Settings settings() {
+        return component().getSettings();
     }
 
-    private void add(final Behavior behavior) {
-        asComponent().add(behavior);
+    default void clearInput() {
+        component().clearInput();
     }
 
-    private ObjectMemento memento() {
-        return select2Choice.fold(
-                single->single.getModelObject(),
-                multi->multi.getPackedModelObject());
+    default boolean isRequired() {
+        return component().isRequired();
     }
 
-    private ObjectMemento convertedInput() {
-        final ObjectMemento convertedInput = select2Choice.fold(
-                single->single.getConvertedInput(),
-                multi->multi.getPackedConvertedInput());
-        return convertedInput;
+    default void setMutable(final boolean mutability) {
+        component().setEnabled(mutability);
     }
 
 }
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2MultiChoiceExt.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2MultiChoiceExt.java
deleted file mode 100644
index fd52d905d4c..00000000000
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2MultiChoiceExt.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.apache.causeway.viewer.wicket.ui.components.widgets.select2;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.wicket.model.IModel;
-import org.wicketstuff.select2.Select2MultiChoice;
-
-import org.apache.causeway.applib.id.HasLogicalType;
-import org.apache.causeway.applib.id.LogicalType;
-import org.apache.causeway.commons.internal.base._Casts;
-import org.apache.causeway.core.metamodel.objectmanager.memento.ObjectMemento;
-import org.apache.causeway.viewer.wicket.model.models.UiAttributeWkt;
-
-import lombok.Getter;
-import lombok.experimental.Accessors;
-
-public class Select2MultiChoiceExt
-extends Select2MultiChoice<ObjectMemento>
-implements HasLogicalType {
-
-    private static final long serialVersionUID = 1L;
-
-    public static Select2MultiChoiceExt create(
-            final String id,
-            final IModel<ArrayList<ObjectMemento>> modelObject,
-            final UiAttributeWkt attributeModel,
-            final ChoiceProviderRecord choiceProvider) {
-
-        return new Select2MultiChoiceExt(id, 
_Casts.uncheckedCast(modelObject), attributeModel, choiceProvider);
-    }
-
-    @Getter(onMethod_ = {@Override}) @Accessors(fluent=true) private final 
LogicalType logicalType;
-
-    Select2MultiChoiceExt(
-            final String id,
-            final IModel<Collection<ObjectMemento>> model,
-            final UiAttributeWkt attributeModel,
-            final ChoiceProviderRecord choiceProvider) {
-
-        super(id, model, choiceProvider.toSelect2ChoiceProvider());
-        logicalType = attributeModel.getElementType().logicalType();
-
-        getSettings().setCloseOnSelect(true);
-        getSettings().setWidth("auto");
-        getSettings().setDropdownAutoWidth(true);
-
-        setOutputMarkupPlaceholderTag(true);
-    }
-
-    public ObjectMemento getPackedModelObject() {
-        return ObjectMemento.packed(this.logicalType(), this.getModelObject());
-    }
-
-    public ObjectMemento getPackedConvertedInput() {
-        return ObjectMemento.packed(this.logicalType(), 
this.getConvertedInput());
-    }
-
-    // -- bug in wicket 8.8.0 -------------------------------------------
-
-    private boolean workaround;
-
-    @Override
-    public void updateModel() {
-        workaround = true;
-        super.updateModel();
-        workaround = false;
-    }
-
-    @Override
-    public Collection<ObjectMemento> getModelObject() {
-        var modelObj = super.getModelObject();
-        if(workaround) {
-            return modelObj==null
-                    ? null
-                    : new ArrayList<>(modelObj);
-        }
-        return modelObj;
-    }
-
-    // ------------------------------------------------------------------
-
-}
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2OnSelect.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2OnSelect.java
index 7feadd70330..8e3b0b664a5 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2OnSelect.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2OnSelect.java
@@ -32,11 +32,13 @@
 import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.request.mapper.parameter.INamedParameters.NamedPair;
 import org.wicketstuff.select2.JQuery;
-
+import org.wicketstuff.select2.Select2Choice;
+import org.wicketstuff.select2.Select2MultiChoice;
 import org.jspecify.annotations.Nullable;
 
 import org.apache.causeway.commons.binding.Bindable;
 import org.apache.causeway.commons.collections.Can;
+import org.apache.causeway.commons.internal.base._Casts;
 import org.apache.causeway.commons.internal.debug._XrayEvent;
 import org.apache.causeway.commons.internal.debug.xray.XrayUi;
 import org.apache.causeway.core.metamodel.object.ManagedObject;
@@ -109,12 +111,11 @@ private void updatePendingModels() {
         .forEach(pair->
             Event.valueOf(pair)
             .ifPresent(event->{
-                if(getComponent() instanceof Select2MultiChoiceExt) {
+                if(getComponent() instanceof Select2MultiChoice 
select2MultiChoice) {
                     var objectMementoFromEvent = 
ObjectMemento.destringFromUrlBase64(pair.getValue());
-                    if(objectMementoFromEvent==null) {
-                        return; // add or remove nothing is a no-op
-                    }
-                    var component = (Select2MultiChoiceExt)getComponent();
+                    if(objectMementoFromEvent==null) return; // add or remove 
nothing is a no-op
+
+                    var component = 
_Casts.<Select2MultiChoice<ObjectMemento>>uncheckedCast(select2MultiChoice);
                     switch(event) {
                     case SELECT:{
                         var newSelection = 
copySelection(component.getModelObject());
@@ -137,8 +138,8 @@ private void updatePendingModels() {
                     }
                 }
                 else
-                if(getComponent() instanceof Select2ChoiceExt) {
-                    var component = (Select2ChoiceExt)getComponent();
+                if(getComponent() instanceof Select2Choice select2Choice) {
+                    var component = 
_Casts.<Select2Choice<ObjectMemento>>uncheckedCast(select2Choice);
                     switch(event) {
                     case SELECT:
                         var objectMementoFromEvent = 
ObjectMemento.destringFromUrlBase64(pair.getValue());
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2ChoiceExt.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/SingleChoice.java
similarity index 55%
rename from 
viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2ChoiceExt.java
rename to 
viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/SingleChoice.java
index 598d155a53f..5655eec2bfd 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2ChoiceExt.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/SingleChoice.java
@@ -21,44 +21,30 @@
 import org.apache.wicket.model.IModel;
 import org.wicketstuff.select2.Select2Choice;
 
-import org.apache.causeway.applib.id.HasLogicalType;
-import org.apache.causeway.applib.id.LogicalType;
+import org.apache.causeway.core.metamodel.context.HasMetaModelContext;
+import org.apache.causeway.core.metamodel.object.ManagedObject;
 import org.apache.causeway.core.metamodel.objectmanager.memento.ObjectMemento;
 import org.apache.causeway.viewer.wicket.model.models.UiAttributeWkt;
 
-import lombok.Getter;
-import lombok.experimental.Accessors;
+record SingleChoice(Select2Choice<ObjectMemento> component)
+implements Select2, HasMetaModelContext {
 
-public class Select2ChoiceExt
-extends Select2Choice<ObjectMemento>
-implements HasLogicalType {
-
-    private static final long serialVersionUID = 1L;
-
-    public static Select2ChoiceExt create(
-            final String id,
-            final IModel<ObjectMemento> modelObject,
-            final UiAttributeWkt attributeModel,
-            final ChoiceProviderRecord choiceProvider) {
-        return new Select2ChoiceExt(id, modelObject, attributeModel, 
choiceProvider);
-    }
-
-    @Getter(onMethod_ = {@Override}) @Accessors(fluent=true) private final 
LogicalType logicalType;
-
-    private Select2ChoiceExt(
+    SingleChoice(
             final String id,
             final IModel<ObjectMemento> model,
             final UiAttributeWkt attributeModel,
             final ChoiceProviderRecord choiceProvider) {
-        super(id, model, choiceProvider.toSelect2ChoiceProvider());
-
-        logicalType = attributeModel.getElementType().logicalType();
+        this(new Select2Choice<>(id, model, 
choiceProvider.toSelect2ChoiceProvider()));
+    }
 
-        getSettings().setCloseOnSelect(true);
-        getSettings().setWidth("auto");
-        getSettings().setDropdownAutoWidth(true);
+    @Override
+    public ManagedObject convertedInputValue() {
+        return getObjectManager().demementify(component.getConvertedInput());
+    }
 
-        setOutputMarkupPlaceholderTag(true);
+    @Override
+    public ObjectMemento objectMemento() {
+        return component.getModelObject();
     }
 
 }

Reply via email to