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
vishal gupta 47vishal gupta 47 

passng values from vf page to controler

how to pass valu from vf page to controler for date datatype
Best Answer chosen by vishal gupta 47
NagendraNagendra (Salesforce Developers) 
Hi Vishal,

Please try below sample code snippet

Visual Force Page:
<apex:page docType="html-5.0" controller="Sample">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                Date: <apex:input type="date" value="{!dat}"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton value="show" action="{!show}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>
</apex:page>

Apex Controller:
public class Sample {
    public Date dat {get;set;}
    public Sample() {
           System.debug('EnteringDate'+dat);
    }
    
    public void show()
    {
           System.debug('EnteringDate'+dat);
    }
}

Hope this helps,Kindly mark this as the best answer if it helps.

Best Regards,
Nagendra.P

All Answers

Prateek Singh SengarPrateek Singh Sengar
Hi Vishal,
You can try using apex:param
 
VF Page
<apex:commandButton value="Go" action="SOME ACTION" rerender="all">
   <apex:param name="dateParam" value="YOUR DATE VALUE" assignTo="{!dateParamVal}"/>
</apex:commandButton>

Apex Class
public Date dateParamVal {get; set;}

Please note the rerender, its important that you have the rerender otherwise the value will not be passed to the apex class. The re-render should have the id of the parent container, it could be a outputpanel or any container element that can be re-rendered.
NagendraNagendra (Salesforce Developers) 
Hi Vishal,

Please try below sample code snippet

Visual Force Page:
<apex:page docType="html-5.0" controller="Sample">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                Date: <apex:input type="date" value="{!dat}"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton value="show" action="{!show}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>
</apex:page>

Apex Controller:
public class Sample {
    public Date dat {get;set;}
    public Sample() {
           System.debug('EnteringDate'+dat);
    }
    
    public void show()
    {
           System.debug('EnteringDate'+dat);
    }
}

Hope this helps,Kindly mark this as the best answer if it helps.

Best Regards,
Nagendra.P
This was selected as the best answer