1

Could not resolve the entity from value binding '{!pizza_name}'. can only be used with SObjects, or objects that are Visualforce field component resolvable.

apex class

public class pizza_menu {
    public string pizza_name{get;set;}
    public integer price{get;set;}
    public void addmenu()
    {
        try

    {
        menu__c m=new menu__c();
        m.name=pizza_name;
        m.price__c=price;
        insert m;

    }

    catch (DmlException e) {
    System.debug('A DML exception has occurred: ' +e.getMessage());
}
    }
}

vf page

<apex:page sidebar="false" controller="pizza_menu">
    <apex:pageBlock title="add the pizza" >
        <apex:pageBlockSection columns="2">
            <apex:form>
                Name of pizza= <apex:inputfield value="{!pizza_name}"/>
               Price= <apex:inputfield value="{!price}"/>
            </apex:form>
        </apex:pageBlockSection>
    </apex:pageBlock>

</apex:page>

2 Answers 2

4

The <apex:inputField> component must be used with fields on an sObject. You do not have an sObject here, just a primitive instance variable on your controller, so you cannot use this component.

The <apex:inputText> component, and other such input components, can be used with controller instance variables.

Alternately, you can store a Menu__c instance, created in your constructor, within your controller class, and reference its field values directly via <apex:inputField>, as for example {! menu.Name }. Your controller would need to declare

public Menu__c menu { get; set; }

and initialize it in the constructor.

0

You cannot bind a class level variable to <apex:inputField>, as input field requires additional meta-data information like label name, data type etc which your class level variable does not have.

You can use <apex:inputText> instead and get those values in controller to build you Menu record. Or else, you can have a Menu instance created and then you can bind fields of Menu directly to <apex:inputField>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .