Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Meaning of the requestAttribute?

Avatar

Level 5
<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. 

1 Accepted Solution

Avatar

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

View solution in original post

8 Replies

Avatar

Level 9

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

 

<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

 

Avatar

Community Advisor

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;

Avatar

Level 5

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

 

Avatar

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