0

I had developed a code when I am adding save code I am getting an error

"Error: Unknown method 'Hospitalcntlr1.save()' "

In the code I want to add all the details of patient in a tabular format once added but it is not coming in the form.

My Visualforce page:

    <apex:page controller="Hospitalcntlr1">
      <apex:Form >
       <apex:pageBlock >        
       <apex:pageBlockSection title="Department">
           <apex:inputField value="{!Dept.Name}"/>
           <apex:inputField value="{!Dept.Department_Number__c}"/>
           <apex:inputField value="{!Dept.Dept_Doctor__c}"/>
           <apex:inputField value="{!Dept.DoctorId__c}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Patient">
           <apex:inputField value="{!patnt.Name}"/>
           <apex:inputField value="{!patnt.patientinfo__c}"/>
           <apex:inputField value="{!patnt.PatientId__c}"/>
           <apex:inputField value="{!patnt.Patient_Joining_Date__c}"/>
           <apex:inputField value="{!patnt.Patient_Out_Date__c}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection >
           <apex:pageBlockTable value="{!patntlist}" var="pat">
                <apex:column value="{!pat.Name}"/>
                <apex:column value="{!pat.patientinfo__c}"/>
                <apex:column value="{!pat.PatientId__c}"/>
                <apex:column value="{!pat.Patient_Joining_Date__c}"/>
                <apex:column value="{!pat.Patient_Out_Date__c}"/>
           </apex:pageBlockTable>
        </apex:pageBlockSection> 
        <apex:pageBlockButtons >
    <apex:commandButton  action="{!save}" value="{!save}"/>
                </apex:pageBlockButtons>    
             </apex:pageBlock>
    </apex:Form>
    </apex:page>

Apex class is:

    public with sharing class Hospitalcntlr1 {
       Public Department__c dept{get;set;}
       Public Patient__c patnt{get;set;}
       public list<Patient__c> patntlist{get;set;}
       public Hospitalcntlr1()
       {
          String ids=Apexpages.currentPage().getParameters().get('id');
           patntlist=[select id, name,patientinfo__c,Patient_Joining_Date__c,Patient_Out_Date__c,Department__C,PatientId__c from patient__c where id=:ids limit 1 ];
          for(Patient__C pet:patntlist)
            {
               dept=[select id,name,Department_Number__c,Dept_Doctor__c,Doctorid__C from Department__c where id=:pet.Department__C];
            }
        }            
    }
  • 3
    Welcome to SFSE. Please don't edit your question to ask something different; instead, create a new question. Otherwise all context is lost and it discourages users from answering. – Mike Chale Nov 20 '13 at 14:25
3

You use the Save action on VF page but not define it on controller So define a method in APEX as you use a Custom controller so use the code snippet like this in your controller:

 public with sharing class Hospitalcntlr1 {
   Public Department__c dept{get;set;}
   Public Patient__c patnt{get;set;}
   public list<Patient__c> patntlist{get;set;}
   public Hospitalcntlr1()
   {
      patnt=new patient();
      String ids=Apexpages.currentPage().getParameters().get('id');
       patntlist=[select id, name,patientinfo__c,Patient_Joining_Date__c,Patient_Out_Date__c,Department__C,PatientId__c from patient__c where id=:ids limit 1 ];
      for(Patient__C pet:patntlist)
        {
           dept=[select id,name,Department_Number__c,Dept_Doctor__c,Doctorid__C from Department__c where id=:pet.Department__C];
        }
    }  
public void Save(){
   patnt.Name=patnt.Name;
   patnt.Patientinfo__c=patnt.Patientinfo__c;
   patnt.Patientid__c=patnt.Patientid__c;
   patnt.Department__c=patnt.Department__c;
   patnt.Patient_Joining_Date__c=patnt.Patient_Joining_Date__c;
   patnt.Patient_out_Date__c=patnt.Patient_out_Date__c;
   insert patnt;
   patnt=new patnt();
 }          
}

and add a line in VF page

 <apex:inputField value="{!patnt.Department__c}"/>

and CommantButton line Should be

<apex:Commandbutton value="Save" action="{!Save}"/>
| improve this answer | |
2

The value attribute should be "Save", not "{!save}". When you use a value attribute with a merge field, it expects a function called getSave. I presume that this wasn't your intent.

| improve this answer | |
  • thanks for the reply but i had written a code to get a table in same page but table is not displaying can u please help me – user4507 Nov 20 '13 at 13:10
  • I'm not sure what "table" you are referring to, as it's not in the question. – sfdcfox Nov 20 '13 at 13:12
  • is my apex class i am refering to patntlist But i am unable to display form in my table – user4507 Nov 20 '13 at 13:20
  • patntlist should be populated in the constructor. – sfdcfox Nov 20 '13 at 13:23
  • 4
    Hi user4507, it seems you are asking a separate question to the original question. Please create a new question with the problem you are now trying to solve. Thanks – BarCotter Nov 20 '13 at 13:43

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.