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
Arjun y 7Arjun y 7 

Unable to pass values from VF Page to Controller

Hi All,

I am unable to pass the values from VF page to controller for date field.
 
<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:pageBlock>
</apex:form>
</apex:page>

Apex Controller:

public class Sample {
    public Date dat {get;set;}
    public Sample() {
           System.debug('EnteringDate'+dat);
    }
}

 
Amit Chaudhary 8Amit Chaudhary 8
NOTE:- You was not able to see Date because you was trying to print in Constructor. Constructor Always execute first at that time date field was blank

Update your code like below
public class Sample {
    public Date dat {get;set;}
    public Sample() {
           System.debug('EnteringDate'+dat);
    }
    
    public void show()
    {
           System.debug('EnteringDate'+dat);
    }
}
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>

Let us know if this will help you

 
Arjun y 7Arjun y 7
Hi Amit,

It didn't work for me. I am still receiving the same null while passing to the action method.

Thank You!
nagendra 6989nagendra 6989
Hi Arjun y 7,

The above solution which amit posted works absolutely fine, please check your code once again.

Best Regards,
Nagendra.P
Amit Chaudhary 8Amit Chaudhary 8
Hi Arjun y 7,

You need to open page then you need to select date after that click on show button it will work.

Let us know if that will help you