Expand my Community achievements bar.

Error during include of component - TextModel cannot be correctly instantiated by the Use API

Avatar

Level 5

When attempting to "Insert component", I get the following error:

 

org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: identifier com.adobe.oursite.core.models.TextModel cannot be correctly instantiated by the Use API.

 

I'm able to add other components, just not the Text Editor component. There are a few discussions that I found online, but nothing I've tried has resolved the issue. 

 

23 Replies

Avatar

Community Advisor

@Codelime Please see the below highlighted code

package com.adobe.business.core.models;

import com.adobe.business.core.utils.Markdown;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import javax.annotation.PostConstruct;

@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class TextModel extends AbstractComponentModel {

@ValueMapValue(name = "backgroundColor")
private String backgroundColor;

@ValueMapValue(name = "textColor")
private String textColor;

@ValueMapValue(name = "text")
private String text;

@ValueMapValue(name = "fullWidth")
private boolean fullWidth;

public String getBackgroundColor() {
return backgroundColor;
}

public String getTextColor() {
return textColor;
}

public boolean getFullWidth() {
return fullWidth;
}

public String getText() {
String out = text;
if (out.contains(".jpg")) {
out.replaceAll(".jpg", ".jpeg/_jcr_content/renditions/cq5dam.web.816.480.jpeg");
} else if (out.contains(".jpeg")) {
out.replaceAll(".jpeg", ".jpeg/_jcr_content/renditions/cq5dam.web.816.480.jpeg");
} else if (out.contains(".png")) {
out.replaceAll(".png", ".jpeg/_jcr_content/renditions/cq5dam.web.816.480.jpeg");
}
return Markdown.parse(text);
}

@PostConstruct
private void initModel() {
Markdown.setResourceResolver(this.getResource().getResourceResolver());
}
}

 

Not sure what is the functionaity written in Markdown.setResourceResolver method as it's specific to your project. Can you comment out these code and see if it works.

Also I have made some changes to the injection property. Removed few of the attributes on the Model annotation. Please retry.

 

Thanks! 

Avatar

Level 5
Hi @Asutosh_Jena_. Do I only comment out the PostConstruct? Maven didn't like it when I also commented out return Markdown.parse(text);

Avatar

Community Advisor

Hi @Codelime 

 

You can return something like return "anystring" for debugging purpose.

return Markdown.parse(text);

 Also for the Post construct, for now you can add some log statement and the existing code.

 

In this way we will be able to identify where the code is failing.