I want pass list index value to sling model.
<sly data-sly-list.img="${guide.itemsList}">
<span>index: ${imgList.index}</span>
<sly data-sly-use.multi="${'com.mycom.....MultiField' @ index=${imgList.index}' " />
This gives me null value at model. I tried to with pass with quotes , it gets passed as string.
Can any one help me to resolve this?
해결되었습니다! 솔루션으로 이동.
토픽은 커뮤니티 콘텐츠를 분류하여 관련성 있는 콘텐츠를 찾는 데 도움이 됩니다.
조회 수
답글
좋아요 수
Hi @LaMind3
After debugging able to find root cause for this issue, its because of datatype mismatch & datatype of itemList.index value is long. please use below updated code where datatype is changed from int to long, value will be injected as expected & it will resolve the issue.
Sightly:
<sly data-sly-use.multi="${'com.mycom.....MultiField' @ index = imgList.index}" />
Model Class:
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class MultiField{
@Inject
private long index;
}
- Manjunath
Hi @LaMind3
Please find below mentioned corrected syntax & try with this.
Sightly:
<sly data-sly-use.multi="${'com.mycom.....MultiField' @ index = imgList.index ,context='number'}" />
Model Class:
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class MultiField{
@Inject
private int index;
}
조회 수
답글
좋아요 수
조회 수
답글
좋아요 수
Try above highlighted updated code, add context='number' & change datatype from String to int.
조회 수
답글
좋아요 수
조회 수
답글
좋아요 수
I verified this code in my local instance & it works fine. please find below debug screenshot where index variable injected with value '2'.
i will suggest you to cross check whether your model class is SlingHttpServletRequest adaptable, if 'yes' then check printing index value(which you are passing to model class) in p tag to make sure proper value is sent to model class.
Sightly:
<sly data-sly-use.multi="${'com.mycom.....MultiField' @ index = 2,context='number'}" />
Model Class:
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class MultiField{
@Inject
private int index;
}
조회 수
답글
좋아요 수
you are missing
@RequestAttribute(name = "index")
private String index;
Please check example here
https://github.com/arunpatidar02/aem63app-repo/blob/master/java/ParamModel.java
Hi @arunpatidar
Using @Inject also we can access request attribute. i think @LaMind3 is missing to add SlingHttpServletRequest in adaptables so its not injecting the value.
@Inject
private int index;
조회 수
답글
좋아요 수
조회 수
답글
좋아요 수
Hi @LaMind3
After debugging able to find root cause for this issue, its because of datatype mismatch & datatype of itemList.index value is long. please use below updated code where datatype is changed from int to long, value will be injected as expected & it will resolve the issue.
Sightly:
<sly data-sly-use.multi="${'com.mycom.....MultiField' @ index = imgList.index}" />
Model Class:
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class MultiField{
@Inject
private long index;
}
- Manjunath
조회 수
답글
좋아요 수
You’re welcome 🙂
조회 수
답글
좋아요 수
hi @Manjunath_K i am also having similar issue,
when I pass the variable in html, i am getting the value.
<sly data-sly-use.productModelV2="${'com.......ProductModelV2' @fileReference='123'}" data-sly-unwrap></sly>
${productModelV2.fileReference} this prints the value.
but in the sling model, under post construct when I am trying to access the variable it gives null, I need the value inside the sling model.
Both tp and mp give null. Please help here
@RequestAttribute(name = "fileReference")
private String fileReference;
@PostConstruct
protected void postConstruct() {
String tp = fileReference;
String mp = getFileReference();
}
public String getFileReference() {
return fileReference;
}
조회 수
답글
좋아요 수
Hi @HinaB1
Please make sure model is adaptable with SlingHttpServletRequest as well
@Model(adaptables = SlingHttpServletRequest.class,
조회 수
답글
좋아요 수
yeah, that's been taken care, still null
조회 수
답글
좋아요 수
Hi @HinaB1
Then it should be working, please check the working examples here:
조회 수
답글
좋아요 수