1

I have to pass language code from the URL to VFP/Apex Code, and the language parameter can be in two different name

  • lang
  • language

so it can be passed like

www.something.com?lang=en_US

or

www.something.com?language=en_US

and I have to get the parameter in apex:page tag and make the Apex Variable 'language' to be in sync with the URL parameter. Please do comment if you want more description.

2 Answers 2

4

You could also just use a conditional expression

<apex:page controller="MyController" language="{!Blankvalue($currentpage.parameters.lang, $currentpage.parameters.language) }">
</apex:page>
2
  • 2
    @TariqueShamim You can also use BlankValue, which is shorter: {!BLANKVALUE($CurrentPage.parameters.lang, $CurrentPage.parameters.language)}
    – sfdcfox
    Jul 22, 2017 at 17:35
  • Updated answer to reflect sfdcfox recommendation
    – Eric
    Jul 22, 2017 at 18:01
0

Code snippet will be like this:

Take URLParameters in a map and loop through the map and retrieve the value.

Controller

public class MyController
{
    public String paramValue {get;set;}
    public MyController()
    {
        Map<String, String> paramMap = ApexPages.currentPage().getParameters();
        for(String str:paramMap.keyset())
        {
            if(str.equalsIgnoreCase('lang') || str.equalsIgnoreCase('language'))
            {
                paramValue = paramMap.get(str);
            }
        }
    }
}

Visualforce

Now, use language attribute and paramValue from Controller property.

<apex:page controller="MyController" language="{!paramValue}">
</apex:page>
1
  • I'd recommend using == instead of equalsIgnoreCase, since they do the same thing, but one is much longer.
    – sfdcfox
    Jul 22, 2017 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .