Passing variable value from sightly to sling model

Avatar

Avatar
Validate 1
Level 1
LaMind3
Level 1

Like

1 like

Total Posts

15 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
LaMind3
Level 1

Like

1 like

Total Posts

15 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
LaMind3
Level 1

01-10-2020

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?

 

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile
Manjunath_K
MVP

01-10-2020

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

Answers (2)

Answers (2)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,444 likes

Total Posts

3,327 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,444 likes

Total Posts

3,327 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

01-10-2020

you are missing

@RequestAttribute(name = "index")
private String index;

 

Please check example here

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/ParamModel.java

Avatar

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile
Manjunath_K
MVP

01-10-2020

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;

 

}