[SalesForce] Bind datepicker value from visualforce page to controller

How to bind the datepicker value to controller. I used onfocus="DatePicker.pickDate" but it was not displaying datepicker in sandbox so i am using as below.

<apex:page standardController="SFDC_Employee__c" extensions="payslipext" sidebar="true" showheader="true">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!SFDC_Employee__c.Month__c}"/>

</apex:pageBlockSection>
<apex:outputLink value="PaySlipPage" id="page">Generate
<apex:param value="{!dateName}" /></apex:outputlink>
</apex:pageBlock>
</apex:form>

</apex:page>

could any one tell me how to bind inputField value="{!SFDC_Employee__c.Month__c} in controller when Outputlink 'Generate' is clicked

Best Answer

You can't do this with an outputlink - that simply generates an anchor tag, so when the user clicks the link their browser will carry out an HTTP GET request to the target URL. Any user input will be discarded. If you want to use a link rather than a button, you should use an apex:commandLink tag, as this will generate a postback of the form containing the user input, and the selected date will automatically be bound to the SFDC_Employee__c.Month__c field.

Depending on what you are trying to achieve with the Generate link, you may need an action method bound to the commandlink, if you want to save the SFDC_Employee__c record, for example you'd have the following:

Page:

<apex:page standardController="SFDC_Employee__c" extensions="payslipext" sidebar="true" showheader="true">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!SFDC_Employee__c.Month__c}"/>

</apex:pageBlockSection>
<apex:commandLink value="Generate" action="{!generate}" id="page">
<apex:param value="{!dateName}" /></apex:outputlink>
</apex:pageBlock>
</apex:form>

</apex:page>

Controller:

public PageReference generate()
{
    // assumes the SFDC_Employee__c record is named 'employee'

    // update or insert the employee record
    upsert employee;

    // send the user to the payslip page for the employee record
    PageReference result=Page.PayslipPage;
    result.getParameters().put(employee.id);
    result.setRedirect(true);

    return result;
}