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
kito kidkito kid 

Display date field on VF

I am trying to show the date as calander on first page load. Then user can change the date.

After that, if button is pressed, that selected date value should be passed to controller.

Now I can't even display the initial value to VF page.

How I can set it up?

 

here is my apex

public Date startDate {get;set;}

 

//constructor

public Class_Test()
 {
        startDate = date.today();

}

 

 

 

here is my VF.

<apex:page controller="Class_Test" id="VF_Class_Test" cache="FALSE" showHeader="FALSE" sidebar="FALSE" tabStyle="blah">

...

<apex:inputField value="{!startDate}"/>

Best Answer chosen by Admin (Salesforce Developers) 
kito kidkito kid

hi TheDoctor,

 

If I set the system.today() in getter of startDate, whenever I try to get the startDate..I will get the today everytime.

My requirement is the user will change the startDate from the datetime picker from UI.

I only want to display the initial value of startDate at formload as today.

 

And I follow this example. and it is working.

 

Thanks everyone.

 

All Answers

TheDoctorTheDoctor

Try this in your class instead:

 

public Date startDate {
    get {
        date d = date.today();
        return d;
    }
    set;
}

 and get rid of the Class_Test() method you have there.

 

Hope this helps.

 

kito kidkito kid

hi TheDoctor,

 

If I set the system.today() in getter of startDate, whenever I try to get the startDate..I will get the today everytime.

My requirement is the user will change the startDate from the datetime picker from UI.

I only want to display the initial value of startDate at formload as today.

 

And I follow this example. and it is working.

 

Thanks everyone.

 

This was selected as the best answer