+ Start a Discussion
Pooja GLPooja GL 

User Language and Locale Values from VF page to Controller

I have a VF pafe which has fields to set language and locale vale, the code for the blcok is below.

<div class="form-group col-lg-12">
<apex:outputLabel for="languageInput" value="{!$ObjectType.User.Fields.languageLocaleKey.Label}"/>
<apex:inputField styleClass="form-control" value="{!u.languageLocaleKey}" id="languageInput" required="true" />
</div>

<div class="form-group col-lg-12">
<apex:outputLabel for="localeInput" value="{!$ObjectType.User.Fields.localesIdKey.Label}"/>
<apex:inputField styleClass="form-control" value="{!u.localesIdKey}" id="localeInput" required="true" />
</div>

I want to get the value selected on these 2 picklist fields and assign it during user creation on controller using an existing class and method.

User u = new user();
u = AccountMatchUtilityTEV.createExternalUserDuringRegistration(account, password, u.languageLocaleKey, u.localesIdKey, 'America/Los_Angeles');

But the new user created is always taking the default values (en_US and en_UK)
Please let me know what is wrong in the above lines of code.


 
Best Answer chosen by Pooja GL
VineetKumarVineetKumar
Sorry for late reply,

Please Initialise the User (get, set one) in the constructor.
u = new User();

Also, if you are doing this in your register method, it will not at all set to the selection that you are doing on the VF Page.
User u = new user();
u = AccountMatchUtilityTEV.createExternalUserDuringRegistration(account, password, u.languageLocaleKey, u.localesIdKey, 'America/Los_Angeles');

All Answers

VineetKumarVineetKumar
I can't see any update or insert call in your above code.
Pooja GLPooja GL
Hi Vineet,
 In the class and method AccountMatchUtilityTEV.createExternalUserDuringRegistration, user is being inserted.
and in the VF page I have a button which calls the function in which the below lines are present.

User u = new user();
u = AccountMatchUtilityTEV.createExternalUserDuringRegistration(account, password, u.languageLocaleKey, u.localesIdKey, 'America/Los_Angeles');

VF page button :
<div class="form-group col-lg-12">
<apex:commandButton action="{!register}" styleClass="btn btn-primary" value="{!$Label.Sign_Up_TEV}"/>
</div>
 
Pooja GLPooja GL
I am pulling all available values in the language picklist of User object using value="{!u.languageLocaleKey}" and in the controller I have used the get; set; as below
public User u {get; set;}

and In the controller I am using u.languageLocaleKey to access the value the user selected on VF page (suppose, User selects French, then u.languageLocaleKey will have the value French?). But I am getting 'Attempt to de-reference null object' on my VF page.

How to access the language value that the user selected in the Page?
VineetKumarVineetKumar
Sorry for late reply,

Please Initialise the User (get, set one) in the constructor.
u = new User();

Also, if you are doing this in your register method, it will not at all set to the selection that you are doing on the VF Page.
User u = new user();
u = AccountMatchUtilityTEV.createExternalUserDuringRegistration(account, password, u.languageLocaleKey, u.localesIdKey, 'America/Los_Angeles');
This was selected as the best answer
Pooja GLPooja GL
Hi Vineet,
Thanks for the answer. Initializing user record in the constructor solved my problem. :) 
VineetKumarVineetKumar
Do mark my answer as the best answer if it helped you.. :)