Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Exteding Form Core Component

Avatar

Level 2

I am getting the below error:

JeetendrakumarSa_0-1726825586446.png

Can somebody help to resolve the issue, please?

Below code in the FormRadio.java:

JeetendrakumarSa_0-1726825725600.png

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @JeetendrakumarSa ,

Return type should be same or its parent.

OptionItem type should be same com.adobe.cq.wcm.core.components.models.form.OptionItem

cross check your imports in implementation class

seems you are return something.core.models.form.radio.OptionItem instead of com.adobe.cq.wcm.core.components.models.form.OptionItem

Thanks

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @JeetendrakumarSa ,

Return type should be same or its parent.

OptionItem type should be same com.adobe.cq.wcm.core.components.models.form.OptionItem

cross check your imports in implementation class

seems you are return something.core.models.form.radio.OptionItem instead of com.adobe.cq.wcm.core.components.models.form.OptionItem

Thanks

Avatar

Community Advisor

Hi @JeetendrakumarSa ,

Delete your OptionItem.java  (as not required)  or rename in case getting used in somewhere else in your project or explicitly mention the return type like this

@Override
public List<com.adobe.cq.wcm.core.components.models.form.OptionItem> getItems() {
return items;
}

 

Find below sample code

package com.abc.core.models;

import java.util.List;

import com.adobe.cq.wcm.core.components.models.form.OptionItem;
import com.adobe.cq.wcm.core.components.models.form.Options;

public interface FormRadio extends Options {

String getTitle();

List<OptionItem> getItems();

}

 

 

package com.abc.core.models;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.wcm.core.components.models.form.OptionItem;
import com.adobe.cq.wcm.core.components.models.form.Options;
import com.adobe.cq.wcm.core.components.util.AbstractComponentImpl;
import lombok.experimental.Delegate;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.*;
import org.apache.sling.models.annotations.injectorspecific.ChildResource;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import org.apache.sling.models.annotations.via.ResourceSuperType;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.List;

@Model(adaptables = SlingHttpServletRequest.class, adapters = { FormRadio.class,
ComponentExporter.class }, resourceType = FormRadioImpl.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)

public class FormRadioImpl extends AbstractComponentImpl implements FormRadio {

public static final String RESOURCE_TYPE = "pmi-atomsmolecules/components/core/form/radio";

@Self
@Via(type = ResourceSuperType.class)
@Delegate(excludes = DelegationExclusion.class)

private Options options;

@PostConstruct
public void init() {
this.options = resource.adaptTo(Options.class);
}

@ValueMapValue
private String title;

@ChildResource
private List<OptionItem> items;

@ValueMapValue
@Default(booleanValues = false)
private boolean textIsRich;

public boolean isRichText() {
return textIsRich;
}

@Inject
public FormRadioImpl(SlingHttpServletRequest request) {
this.options = request.adaptTo(Options.class);
}

public Object getFormId() {
return FormUtil.getInheritedFormId(resource);
//return null;
}

@Override
public String getExportedType() {
return FormRadioImpl.RESOURCE_TYPE;
}

@Override
public String getTitle() {
return title != null ? title : options.getTitle();
}


@Override
public List<OptionItem> getItems() {
return items;
}

private interface DelegationExclusion {
String getExportedType();
String getTitle();
}

}

 

Thanks