I am working on a AEM 6.1 to 6.3 Migration project. After replacing all the deprecated methods/api's like admin resource resolver and WCMUse with getServiceResourceResolver and WCMUsePojo respectively, my application is throwing an error on sling models (as below). Basically it's not getting instantiated -
Error Says:
Code is written like:
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.wcm.api.Page;
import com.google.gson.Gson;
/**
* Sling Model for getting selectValue.
*/
@Model(adaptables = SlingHttpServletRequest.class)
public class SelectValue {
private static final Logger LOG = LoggerFactory.getLogger(SelectValue.class);
@Inject
private Page currentPage;
@Inject @Self
private SlingHttpServletRequest request;
private String localCode;
@PostConstruct
public void init() {
localCode = LanguagesUtil.getLanguageLocaleCode(currentPage.getPath());
..........
Is there any issue with the code written?
Has anyone encountered this type of issue while migrating aem 6.1 to 6.3?
Solved! Go to Solution.
Thankyou All, This issue has been resolved.
It was related to the node property (jcr:title), which was coming as null as it was not present in the CRX/DE for that particular node, So, it was throwing an error.
Check the :
Can you please test this article/package in your instance:- Creating a custom Touch UI Grid Component for Adobe Experience Manager
// This AEM 6.3 Sling Model article that works and does not throw any exception.
Views
Replies
Total Likes
Hi @kautuk_sahni !
Can I get the another URL for Creating a custom Touch UI Grid Component for Adobe Experience Manager ? I'm not able to access it. Its giving "404. Page not found."
I want to try that, so please provide me with other source if possible. Thanks
Views
Replies
Total Likes
That article is unpublished now. But, closest to it is https://aem4beginner.blogspot.com/creating-custom-touch-ui-grid-component.
Views
Replies
Total Likes
Check the answers Kautuk gave. In addition, if you can give the log trace, may be we can clearly identify what is the exact root cause.
Views
Replies
Total Likes
Test this code on a fresh AEM install and see if it throws the same error. This will tell us if the issue is with the code or upgraded AEM version.
Views
Replies
Total Likes
Thankyou All, This issue has been resolved.
It was related to the node property (jcr:title), which was coming as null as it was not present in the CRX/DE for that particular node, So, it was throwing an error.
Hi,
The solution for this error is to use @Optional annotation while trying to inject fields using Sling Models. The reason is as follows;
When you are using Sling Models for injecting fields and you try to drag and drop the component for the first time, the model will check for the all the injected values. Since you are dropping the component for the first time and there are no values stored for it in the JCR and as result the error will be thrown. But when we use the @Optional annotation the injection strategy will be considered as optional for the field and hence it won't check for the values.
Please refer to following link for deeper knowledge on Sling Models:
Regards,
Views
Likes
Replies
Views
Likes
Replies