Fetching Data from node using model
I have one component(Name, Price, Button Label) which has button . Whenever button is clicked it should redirect to new page and fetch the same data and print there.
I am trying to use href with parameters p and name using which I coul get the data and show in new component present there. I have written below code which is giving error org.apache.sling.scripting.sightly.render.ObjectModel Cannot access method name on object com.sample.core.models.DescriptionModel@76c56976
Tried restarting aem, refreshing bundle giving build etc nothing worked
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class DescriptionModel {
private final Logger logger = LoggerFactory.getLogger(getClass());
@SlingObject
SlingHttpServletRequest request;
@OSGiService
private transient ResourceResolverFactory resolverFactory;
public ValueMap getResource() throws LoginException {
ResourceResolver resolver=request. getResourceResolver();
Resource resource = resolver.getResource(request.getParameter("p"));
logger.info("RESOURCE IS {}",resource.getChild("jcr:content/"+request.getParameter("name")).getPath());
return resource.getChild("jcr:content/"+request.getParameter("name")).getValueMap();
}
public String getName() throws LoginException {
ValueMap properties=getResource();
return (String) properties.get("name");
}
public int getPrice() throws LoginException {
ValueMap properties=getResource();
return (int) properties.get("price");
}
public String getBtnLabel() throws LoginException {
ValueMap properties=getResource();
return (String) properties.get("btnLabel");
}