0

I tried to pass the input field variable value(as provided by the user) to a global variable in the controller. I have the following code.

<div class="Modal">
    <apex:pageBlockSectionItem id="DateTimeofComment">
        <apex:outputLabel>Comment Sent Date</apex:outputLabel>
        <apex:inputfield id="CommentDate" value="{!AModel.dateTimeInput}" />
        <apex:commandButton action="{!AModel.save}" value="Save" id="saveCommentButton" />
    </apex:pageBlockSectionItem>

AModel is an extension class. In the AModel class I have the global variable

public DateTime dateTimeInput {get;set;}
public void save() {
    //Save Code.............
}

What is happening is that whenever I am trying to save the visualforce page code given above it is throwing the following error.

Error:

Could not resolve the entity from <apex:inputField> value binding {!AModel.dateTimeInput}. can only be used with SObjects, or objects that are Visualforce field component resolvable.

Can anyone tell me how this issue will be ressolved?

4

A good solution to this is to use a proxy object in the controller to capture the dateTime value

public Event evt { // proxy object, fld StartDateTime is creatable
  get {
    if (this.evt == null)
         this.evt = new Event();
    return this.evt; 
  set;
}  

... elsewhere in your controller (like in the custom save action method, you can use this.evt.startDateTime to reference the user-entered datetime.

Then your VF page is:

    <apex:pageBlockSectionItem id="DateTimeofComment">
        <apex:outputLabel>Comment Sent Date</apex:outputLabel>
        <apex:inputfield id="CommentDate" value="{!evt.startDateTime}" />
        <apex:commandButton action="{!save}" value="Save" id="saveCommentButton" />
    </apex:pageBlockSectionItem>

The advantage of this approach is you leverage the builtin SFDC datetime picker and you can avoid all the hassle of parsing datetimes.

| improve this answer | |
  • Now that is something amazing. – Mr.Frodo Jun 8 '16 at 6:01
0

The error which you are getting describe this:

If it's not an sObject field, you have to use one of the typed input tags. In your case, you would use <apex:inputText>.

Additional options include <apex:inputcheckbox> and <apex:inputTextArea> to handle other data types.

| improve this answer | |
  • I am appending the date picker to it. If I use <apex:inputText> it would not be a input date field. Is there any other way? @Mr.Frodo – Rimii Jun 8 '16 at 5:26
  • There are several ways to achieve this, check this: Datepicker in Visualforce page – Mr.Frodo Jun 8 '16 at 5:47
  • One more nice post on this. – Mr.Frodo Jun 8 '16 at 5:55

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.