For some condition, I have replaced a pageModel with a default pageModel and the page contents load properly. The page loads properly. In some cases, I additionally have to change the localization from A to D where A is my webRequestContext.localization and D is the localization of the default pageModel. In this case, the Navigation sitemap that comes from the NavigationController loads the sitemap based on webRequestContext.localization.

How can I change webRequestContext.localization without redirecting to the default page?

if(redirectSiteLang.equals("en")) {
        localization = localizationfactory.createLocalization("10", "/en");
    }else if (redirectSiteLang.equals("ar")) {
        localization = localizationfactory.createLocalization("11", "/ar");
request.setAttribute(PAGE_MODEL, pageModel); // new pageModel set
request.setAttribute(LOCALIZATION, localization); // new localization set

When I do a webRequestContext.getPage(); it prints all the regions with their respective include page ids pointing to the 11 publication.

meta={regions=RegionModelSetImpl(modelMapByName={WebSiteNav=AbstractViewModel(extensionData=null, htmlClasses=null,
        xpmMetadata={IncludedFromPageID=tcm:11-126524-64, IncludedFromPageTitle=WebSiteNav, IncludedFromPageFileName=web-site-nav}, mvcData=MvcDataImpl(controllerAreaName=Framework, controllerName=Region, actionName=Region, areaName=Core, viewName=WebSiteNav, regionAreaName=null, regionName=null, routeValues={}, metadata={}))
  • Why do you want to change the Localization? Is the Localization not resolved correctly based on the page URL? Feb 6, 2019 at 15:54
  • In one of the cases, user might be in the root localization (so neither en nor ar) but I need to show the content from appropriate localization based on user's history.
    – Rache
    Feb 6, 2019 at 18:48
  • @rickpannekoek to add to my above comment, even though I manage to load the pageModel of the required publication some of the other components in that page comes from the core controller which reads the localization from the webRequestContext. Any way to refresh the webRequestContext localization without redirecting.
    – Rache
    Feb 7, 2019 at 6:50

1 Answer 1


In your example use case, the WebRequestContext doesn't really change: the Web Request was done in a particular Localization context (based on the URL of the Web Request).

But I understand you want to be able to retrieve content from another Localization? Note that the ContentProvider methods take a Localization parameter.

  • if change the localization based on a url in other language WebRequestContext.Localization = Sdl.Web.Common.Configuration.SiteConfiguration.LocalizationResolver.ResolveLocalization(uri); any issue you foresee?
    – Lucas Liu
    Sep 8, 2020 at 19:31
  • 1
    No, I don’t foresee issues with doing that. Alternatively, you could create your own Localization Resolver which has this fallback logic built-in. Sep 9, 2020 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.