Meaning of the requestAttribute? | Community
Skip to main content
Level 6
July 8, 2022
Solved

Meaning of the requestAttribute?

  • July 8, 2022
  • 2 replies
  • 2770 views
<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.
Best answer by BrianKasingli

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}"

2 replies

Manu_Mathew_
Community Advisor
Community Advisor
July 9, 2022

@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

 

anasusticAuthor
Level 6
July 11, 2022

Thank you @manu_mathew_ 

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
July 11, 2022

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;

anasusticAuthor
Level 6
July 11, 2022

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}"

 

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

Yes, it is working.