Meaning of the requestAttribute? | Community
Skip to main content
Level 6
Jul 8, 2022 8:53 PM UTC
Solved

Meaning of the requestAttribute?

<sly data-sly-resource="${item.imagePath @ resourceType='zkb/components/content/image', wcmmode='disabled', requestAttributes=model.breakpoints}"
data-sly-unwrap></sly>

Hi,

Can someone explain how to intreprete the requestAttribute in the template above?

 

 model. breakpoints are evaluated from the model:

private static final Map<String, String> BREAKPOINTS_SIZES = Map.of("small", "300x200", "middle", "400x500", "normal", "600x750", "large", "600x750");

 and are a map. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
BrianKasingli
BrianKasingliAccepted solution
New Participant
Jul 14, 2022 7:48 PM UTC

Hi Brian

I am sorry, but I am not sure which code you refer to?


data-sly-resource="${item.imagePath @ resourceType='xxx/components/content/image', wcmmode='disabled', requestAttributes=model.breakpoints}"

8 replies

BrianKasingli
New Participant
Jul 11, 2022 2:22 AM UTC

From what I can see, you are calling an AEM Component, and passing the requestAttributes parameter to your Sling Model backend. 

 

If you are using Sling Model, from the backend, to capture the requestAttribute will be:

 @RequestAttribute
    private String href;

If you are using WCMUsePojo, from the backend, to capture the requestAttribute will be:

get("href", String.class);

 

You can see how to pass data from Sightly to Sling Model

How to Pass Data Parameters to Sling Modal from Sightly HTL Component

 

You can see how to pass data from Sightly to WCMUsePojo

How to Pass Data Parameters to WCMUsePojo from Sightly HTL Component

@RequestAttribute private String href;

Translate
anasusticAuthor
Level 6
Jul 11, 2022 7:21 AM UTC

Thank you @briankasingli 

I believe I use in the first approach in my implementation (passing from Sightly to Sling Model).

If I understand your very helpfull examples correctly, then @RequestAttribute in the Model comes from the Slightly HTL Component data-sly-use.linkResolve="${'com.sourcedcode.core.utils.use.LinkResolve' @ href='https://sourcedcode.com'}"?

What I do not understand in my example are the data parameters that are passed with a comma. I understand the item.imagePath is a resource that is passed to the image component under resrouceType and then additionally I have to data parameters that are passed to the model?

data-sly-resource="${item.imagePath @ resourceType='xxx/components/content/image', wcmmode='disabled', requestAttributes=model.breakpoints}"

 

Translate
BrianKasingli
New Participant
Jul 13, 2022 11:45 PM UTC

is this code working? I tried it, does not work. 

Translate
Manu_Mathew_
New Participant
Jul 9, 2022 1:18 AM UTC

@anasustic  Aslo ref. https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/requestattributes-data-sly-include/m-p/371183

 

<sly data-sly-use.settings="com.adobe.examples.htl.core.hashmap.Settings" data-sly-include="${ 'productdetails.html' @ requestAttributes=settings.settings}" / 

 

 And 'requestAttributes' can be passed from Java class.

 

public class Settings extends WCMUsePojo {

  // used to pass is requestAttributes to data-sly-resource
  public Map<String, Object> settings = new HashMap<String, Object>();

  @Override
  public void activate() throws Exception {
    settings.put("order", "ascending");
  }
}
@Model(adaptables=SlingHttpServletRequest.class)
public class ProductSettings {
  @Inject @Optional @Default(values="empty")
  public String order;

}
here 'order' is injected via the Map from the Use-class

 

Translate
anasusticAuthor
Level 6
Jul 11, 2022 7:10 AM UTC

Thank you @manu_mathew_ 

Translate