1

I am trying to get a date value in a VF page and transfering it to a custom controller using a custom object reference Ticket__c. This says i am trying to deference a null object. How can i get the input from VF page into thee contoller.

<apex:inputField label="FromDate"  value="{!fromDate}" id="fromDate"/><br/>
<apex:inputField label="ToDate" value="{!toDate}" id="toDate"/><br/>
`

custom contoller

public class ReportController {

public DateTime fromDate;
public DateTime toDate;


public void fetchRecords()
{

system.debug(fromDate);
system.debug(toDate);
.
.
 //other code
}
1

1: You need use property for data bindings

public DateTime fromDate {get; set;}
public DateTime toDate {get; set;}

2: <apex:inputField> you can use only with SObject, in that case appropriate control will be generated. In your your case, you need use <apex:inputText> or something like that.

| improve this answer | |
0
<apex:input type="date" label="FromDate"  value="{!fromDate}" id="fromDate"/><br/>
<apex:input type="date" label="ToDate" value="{!toDate}" id="toDate"/><br/>

` custom contoller

public class ReportController {

public Date fromDate;
public Date toDate;


public void fetchRecords()
{

system.debug(fromDate);
system.debug(toDate);
.
.
 //other code
}

You need to use apex:input with type date for this to working. But kee this thing in mind that this will not work with FF or other browser. Also keep your Doctype="html 5.0".

Second option is use apex:inputfield with some object field example: Opportunity close Date or any other field in this way you will get your value> when you submit the form you will get updated value in your controller.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.