Why can not inject value from cq dialog in sling model
I am getting trouble with sling model in AEM 6.3. The field value productData must be injected as expected with value whenever we change the value of pathbrowser in the component's dialog but It just gets null. I did try some solutions from the internet but it does not work.
Here is some referenced link I followed:
https://techrevel.blog/tag/sling-model/
Adobe CQ/Adobe AEM: How to use Sling Models in CQ5.6
My model code
import com.day.cq.wcm.api.Page;
import com.adobe.cq.commerce.api.Product;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Optional;
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
@Model(adaptables = {SlingHttpServletRequest.class, Resource.class})
public class ProductDetailsModel {
@SlingObject
private SlingHttpServletRequest request;@SlingObject
private SlingHttpServletResponse response;@ScriptVariable
private Page currentPage;@Inject
@Named("productData")@Optional
private String productData;@PostConstruct
public void init(){int i = 1 + 2;
Product product = request.getResourceResolver().getResource(productData).adaptTo(Product.class);
}
public String getProductData() {
return productData;
}
public void setProductData(String productData) {
this.productData = productData;
}
}
My pathbrowser in dialog content:
<column
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container"><items jcr:primaryType="nt:unstructured">
<productData
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/pathbrowser"
fieldDescription="Display in page"
fieldLabel="Path"
name="./productData"/></items>
</column>
I really do not know what I did wrong here. Please help me resolve this.