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
Jezza83Jezza83 

Displaying the Salesforce Calendar Link on VF Page

I am trying to get the Salesforce Calendar Link to display on my VF page next to my field but am having no joy...

 

 

// Get Commencement Date for Add and Change Operations

public Date getCommencementDate() {

return null;

}

// Set Commencement Date for Add and Change Operations

public void setCommencementDate(Date CommencementDate) {

this.CommencementDate = CommencementDate;

}

 

---------------------------------------------

 

<apex:inputText value="{!CommencementDate}" />

 

 Salesforce won't allow me to display the input field as type inputField as it is not an SObject field. I have some javascript that displays a popup calendar but I would really like to use the native functionality if possible to retain the look and feel of the UI for users (as the javascript calendar actually pops up in a separate window).

 

Any help would be greatly appreciated.... 

 

Message Edited by JDog on 03-02-2010 11:57 PM
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I don't think you'll be able to use the createddate, as that's a read only field.

 

Yes, you can use any sobject, I went with a dummy as I didn't want to pollute my business objects with unused fields, plus I needed dates in a number of pages.

 

Here's some snippets - it looks like you have the idea.

 

Controller:

 

 

public Field_Container__c fieldContainer {get; set;} public MyController() { fieldContainer=new Field_Container__c(); } public DoSomethingWithDates() { Date d1=fieldContainer.Date_1__c; Date d2=fieldContainer.Date_2__c; // do stuff. }

 

 

 

 

Page:

 

 

 

<apex:pageBlockSection> <apex:label value="First Date"/> <apex:inputField value="{!fieldContainer.Date_1__c}"/> </apex:pageBlockSection>

 

 

All Answers

bob_buzzardbob_buzzard

The way I've done this before is:

 

Create a "dummy" custom object that contains as many date/datetime fields as I need.

Instantiate one of these in the controller.

Add inputfield components to the page, backed by the various fields of my dummy object.

In the controller, extract the fields from the dummy object and use as needed. 

 

I use a custom dummy object, so that I have no dependency on the end user of the page being a CRM user and requiring access to standard objects.

 

 

Jezza83Jezza83

Thanks Bob but just a little confused on this one - so I create say SObject Example__c and have a field in it Date__c (no records ever get saved to this SObject) but a user can input the date into this field and then I can grab the value and use it in my class ?

 

....basically I am trying to pass the value back to use in a search of created dates of records - could I just use the CreatedDate field or a custom date field on the actual object ? instead of creating the SObject ?

 

If not is the below similar to what you are talking about ?

 

 

public Example__c date { get { return date;} set { date = value;} }

 

public Class () {date = new Example__c(); }

 

 

 

Message Edited by JDog on 04-02-2010 12:16 AM
bob_buzzardbob_buzzard

I don't think you'll be able to use the createddate, as that's a read only field.

 

Yes, you can use any sobject, I went with a dummy as I didn't want to pollute my business objects with unused fields, plus I needed dates in a number of pages.

 

Here's some snippets - it looks like you have the idea.

 

Controller:

 

 

public Field_Container__c fieldContainer {get; set;} public MyController() { fieldContainer=new Field_Container__c(); } public DoSomethingWithDates() { Date d1=fieldContainer.Date_1__c; Date d2=fieldContainer.Date_2__c; // do stuff. }

 

 

 

 

Page:

 

 

 

<apex:pageBlockSection> <apex:label value="First Date"/> <apex:inputField value="{!fieldContainer.Date_1__c}"/> </apex:pageBlockSection>

 

 

This was selected as the best answer
Jezza83Jezza83
Cheers thanks for the help Bob
craigmhcraigmh

Wow, that works great. I used this code in a Component, and made a nice little date picker.