You need to sign in to do that
Don't have an account?
Picklist values not rendering default values when object is instantiated AFTER page load.
In the dev docs, it states:
"Beginning with API version 20.0, an inputField matched to a field with a default value has the default value prepopulated on the Visualforce page."
This functionality works fine when the object is instantiated in the constructor on page load. However, I need to develop a page that renders different objects on a certain part of the page based on the click of a button by the user. When I instantiate this object in a controller action method from the user's click, the default value does NOT appear. Is this standard functionality? I am using an <apex:inputField /> as the document describes.
Thanks in advance for the help!
Hi,
If you can please share your code.
Could you please share you code.
I wrote up a very quick example to illustrate what I am trying to describe:
Visualforce Page:
Apex Controller:
The custom field "Days_Dispensed_Mail_Order__c" is a picklist with several values, and the default set to "90".
When the page first loads, the picklist displays "90", as it should, because it is the default value. However, after you click reRenderBlock to rerender the page and instantiate a new instance of the pg_Protocol_Guide__c object "plan", the picklist displays the value "--None--", which is incorrect.
It seems that when the visualforce page is first loaded, it defaults all picklist values to their correct defaults. BUT, if you instantiate the object AFTER the page first loads, it doesn't not respect the defaults. Does this make sense?
try this changes in reRernderBlobk method.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Chamil,
I appreciate the quick reponse. I understand that is a solution but it is not what I am looking for. The problem is, though it will default the value, this value is being set in code. If an end user ever wants to change this value, they would have to edit and redeploy code which is simply not acceptable for this project. The goal is to design the system to require as little developer maintanance as possible in the future, meaning I would want the users to change this default value through declarative setup.
Are defaults only being set on pageload simply a limit of apex and visualforce that I need to deal with? Or am I overlooking something else?
yeah, i think thats a bug in the system. only way to get the default value is to refresh the page on button click.
Rohit,
Actually, it seems that even if you refresh the entire page, the default value still doesn't come through. It ONLY works when the page is first loaded.
hello,
if you want the default value on refreshing the page, change your controller action method to the following code:
Rohit,
Thats not really rerendering the page, that seems like a hard redirect, causing the entire page to be regenerated from SFDC. Any values that were previously entered would all be lost as the page is created from scratch, illustrating again that picklists only default when the page is first loaded, right? I meant that even reRendering the entire page by not including a "reRender" attribute on the <apex:CommandButton /> doesn't populate picklists with defaults.
You are correct. Picklists only default when the page is first loaded making the Winter 11 announcement incomplete in some respect. This is a bug and I reckon should be posted on Ideas.
I would vote for this!