1

I'm trying to get a picklist to render in the proper language in a Visualforce Page using SLDS styling. When localization wasn't a concern, there was a tiny bit of code:

public with sharing class MyController
{
    public List<PicklistEntry> myOptions
    {
        get
        {
            return MyObject__c.MyField__c.getDescribe().getPicklistValues();
        }
    }
}

And the markup looked roughly as follows:

<div class="slds-...">
    <label class="slds-..." for="myField">
        {!$ObjectType.MyObject__c.fields.MyField__c.label}
    </label>
    <div class="slds-...">
        <div class="slds-...">
            <select class="..." type="text" id="myField">
                <option>--</option>
                <apex:repeat var="option" value="{!options}">
                    <option value="{!option.value}">{!option.label}</option>
                </apex:repeat>
            </select>
        </div>
    </div>
</div>

However, now that they're just instances of PicklistEntry pulled from the back end, setting the language attribute on the <apex:page> tag will have no effect.

I tried changing the <apex:repeat> as follows:

<apex:repeat ... value="{!$ObjectType.MyObject__c.fields.MyField__c.picklistValues}">

However, I get this error:

Unsupported type common.api.soap.wsdl.PicklistEntry encountered.

Is there any way to render picklist options using a <select> element in such a way that they'll translate using the language attribute? I don't want to use a Custom Label for each, I want it to scale with the picklist field configuration.

2

I was actually able to solve it by caching a List<MyObject__c> with each possible value of MyField__c populated, then using an <apex:outputText> between each <option> tag. Using this approach, the picklist values are translated based on the lang attribute set on your <apex:page>.

Controller

public List<MyObject__c> options
{
    get
    {
        if (options == null)
        {
            options = new List<MyObject__c>();
            for (PicklistEntry entry : MyObject__c.MyField__c.getDescribe().getPicklistValues())
            {
                options.add(new MyObject__c(MyField__c=entry.getValue()));
            }
        }
        return options;
    }
    private set;
}

Markup

<select ...>
    <option value="{!''}">--</option>
    <apex:repeat value="{!options}" var="option">
        <option value="{!option.MyField__c}">
            <apex:outputText value="{!option.MyField__c}" />
        </option>
    <apex:repeat>
</select>
| improve this answer | |
0

Short answer - No

Documentation doesn't offer any known pointers to support for this, likely due to having to convert to a complex type (SelectOption / PicklistEntry) and not a common data type such as String, Date, Boolean. There is no way to directly serialize to that type in VF using language attributes without having to pull the values from a controller where it has been serialized into a SelectOption / PicklistEntry. This would be cool if we could do this, but I really don't thing that the platform on a base level has the power to do that with language attributes due to the complexity of the type.

| improve this answer | |
0

I think at time of writing it might be a known issue: https://success.salesforce.com/issues_view?id=a1p30000000SvOnAAK

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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