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

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

browser url in sling model

Avatar

Level 6

Hi Team,

 

How I  can get browser URL in sling model for example  if the browser URL is https://www.xyz.com/ i need to get this url  in sling model so that i need to do some update based on condition.

can some one help here.

1 Accepted Solution

Avatar

Correct answer by
Level 7

AdobeID24_0-1664301069567.png

above is tested and working you can use like that 

 

View solution in original post

6 Replies

Avatar

Level 2

Hi,

 

If you are adapting request to your model, then you can use 

@SlingObject
private SlingHttpServletRequest request;

then, get uri from request using 

request.getRequestURI()

 

Avatar

Level 7

In Sling model, take request object

 @Self
 private SlingHttpServletRequest request;

and call request.getRequestURI() to get domain

Avatar

Level 6

@HeenaMadan ,

 

I tried how u explained but always i am getting request is null;

Any other option i can try ??

Avatar

Level 7

Did you adapt model with SlingHttpServletRequest?

@Model(adaptables = {
SlingHttpServletRequest.class}

 Can you share your model?

Avatar

Correct answer by
Level 7

AdobeID24_0-1664301069567.png

above is tested and working you can use like that