Model's adaptable is request - bug with @Default

Avatar

Avatar
Give Back 3
Level 2
Aryan12345
Level 2

Likes

6 likes

Total Posts

32 posts

Correct reply

0 solutions
Top badges earned
Give Back 3
Give Back
Ignite 1
Validate 1
Boost 5
View profile

Avatar
Give Back 3
Level 2
Aryan12345
Level 2

Likes

6 likes

Total Posts

32 posts

Correct reply

0 solutions
Top badges earned
Give Back 3
Give Back
Ignite 1
Validate 1
Boost 5
View profile
Aryan12345
Level 2

29-11-2018

Hello Experts!

I have a model adaptable from request. I have resource depend injections marked with @Via("resource"). There are some where i put the tag @Default(values="default text");.

Now comes the interesting part. Even when i enter the value in the dialog for that item, it does not take that value but only default value.

Now when i change the model to accept "adapt" from resource, then the real value gets picked up and when it is not available default values get picked up which is the accepted behavior.

Is this a known issue with model adaptable from request and @Default?

please let me know.

thanks all,

YAdhu

Replies

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,314 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,442 likes

Total Posts

3,314 posts

Correct reply

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

29-11-2018

Hi,

May be using request type it is not able to find and adapt property.

try below:

@Model(adaptables=SlingHttpServletRequest.class) public interface MyModel

// will return request.getResource().getValueMap().get("propertyName", String.class)

@Inject @Via("resource")

String getPropertyName();

}

Avatar

Avatar
Give Back 3
Level 2
Aryan12345
Level 2

Likes

6 likes

Total Posts

32 posts

Correct reply

0 solutions
Top badges earned
Give Back 3
Give Back
Ignite 1
Validate 1
Boost 5
View profile

Avatar
Give Back 3
Level 2
Aryan12345
Level 2

Likes

6 likes

Total Posts

32 posts

Correct reply

0 solutions
Top badges earned
Give Back 3
Give Back
Ignite 1
Validate 1
Boost 5
View profile
Aryan12345
Level 2

29-11-2018

Hi Arun,

Not sure I understood. My question is that @Default forces itself upon the dialog value also in case the adaptable in Request and works fine if adaptable in resource.

Any clues?

Note: the behavior is consistent after testing.

thanks,

Yadhu

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

29-11-2018

Can you show your code please.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

29-11-2018

This could be a bug. I have never myslef seen an issue when i use:

adaptables = Resource.class

Avatar

Avatar
Give Back 3
Level 2
Aryan12345
Level 2

Likes

6 likes

Total Posts

32 posts

Correct reply

0 solutions
Top badges earned
Give Back 3
Give Back
Ignite 1
Validate 1
Boost 5
View profile

Avatar
Give Back 3
Level 2
Aryan12345
Level 2

Likes

6 likes

Total Posts

32 posts

Correct reply

0 solutions
Top badges earned
Give Back 3
Give Back
Ignite 1
Validate 1
Boost 5
View profile
Aryan12345
Level 2

29-11-2018

No issues with resource.class. only with request.class. thats confirmed.

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,314 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,442 likes

Total Posts

3,314 posts

Correct reply

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

30-11-2018

I think when you adapt as request, the dialog field is not consider as adaptable for request type and thats why it is taking default but If you can try something like below, not sure I am just guessing.

You can use @ValueMapValue without via

@ValueMapValueinjectionStrategy, name and viavaluemapInjects a ValueMap value. If via is not set, it will automatically take resource if the adaptable is the SlingHttpServletRequest. If name is not set the name is derived from the method/field name.

@ValueMapValue

  @Default(booleanValues = false)
  private boolean showPrice;