function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
krishnagkrishnag 

how can i make a picklist value default

hi,

 

i have a visualforce page with two picklist values month and year. How can i make the values in the picklist default to current month and current year when the page loads,

SteveBowerSteveBower

In the constructor for your Controller, or ControllerExtension, set the values for the picklist fields.

This way they will be instantiated and set before the page renders and the getters are called to display them.

Best, Steve.

sajm_2010sajm_2010

hi,

      You can call action on the page load.call 'Action' in <apex:page action={!Prorprty}> and that function you can invoke through controller and set the value of picklist value in that method with system.now().

krishnagkrishnag

i tried both the ways its getting error when we give system.now since its a datetime the format changes right

krishnagkrishnag

i there anyway we can write a setmethod for that and give the current month on the field

 

like

 

public  String setmonth()

{

   this.month = THIS_MONTH;

 

return month;

 

}

 

SteveBowerSteveBower

Do you mean something like:

 

String m = datetime.now().format('mmmm');

String y = datetime.new().format('yyyy');

 

Best, Steve