Expand my Community achievements bar.

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

Community Advisor

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

Community Advisor

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