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
kaulsaksoftkaulsaksoft 

Null Object in the Extension Controller

When calling a method in VisualForce page using Extension Controller the OBject in the constructor gives the value as null

 

I am trying to call a method of Extension Controller in the VisualForce page which calculates some value and renders the output. But it display a null value

wesnoltewesnolte

Hey

 

Can you post your page and extension code please? Or just he relevant parts of it..

 

Cheers,

Wes

kaulsaksoftkaulsaksoft

<apex:page standardController="CustomerFinancialDetail__c" extensions="CustomerFin" tabStyle="CustomerFinancialDetail__c" >
<apex:outputPanel id="vehicleLoan">
<apex:pageBlockSection title="Vehicle Loan" columns="2" rendered="{!CustomerFinancialDetail__c.Vehicle_Loan__c == true}">
<apex:pageblockSectionItem >
<apex:outputLabel value="Vehicle loan monthly EMI"/>
<apex:inputtext value="{!CustomerFinancialDetail__c.Vehicle_loan_monthly_EMI__c}">
<apex:actionsupport event="onchange" action="{!calculate}" rerender="summation" />
</apex:inputtext>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="Total No of Years Of Loan" />
<apex:inputfield value="{!CustomerFinancialDetail__c.Total_no_of_years_of_loan_for_Vehicle__c}"/>
</apex:pageblockSectionItem>

<apex:outputpanel id="summation">
<apex:pageblocksection title="Total Current Value of All Liabilities">
<apex:pageblockSectionItem >
<apex:outputLabel value="Total Current Value of All Liabilities"/>
<apex:outputtext value="{!total}"/>
</apex:pageblockSectionItem>
</apex:pageblocksection>
</apex:outputpanel>

Hi

 

This is my Apex Page where on the onChange event I call a funtion Caluculate written in my Extension Controller. After doing sum calculation I render it through the total varaiable.

 

Below is the Controller Extension Code

 

 

public class CustomerFin
{
private CustomerFinancialDetail__c Cfc;
public Double total;

public CustomerFin(ApexPages.StandardController controller)
{
this.Cfc= (CustomerFinancialDetail__c)controller.getRecord();
}

public Double getTotal()
{
system.debug('AAAAAAA');
return total;
}

public void calculate()
{
total= Cfc.Vehicle_loan_monthly_EMI__c +10.0;
system.debug('111111 '+ Cfc.Vehicle_loan_monthly_EMI__c);
system.debug('22222222 '+ total );
}

}

 

 

The problem is that when I try to do the calculation  in the Extension Controller the values from the page into the Controller give the values as null.

wesnoltewesnolte

When you navigate to your page are you putting the id of the object in the URL using an 'id' parameter? The reason I ask is that the standardtroller uses this parameter to 'instantiate' the object you want to work with..

 

Wes

Message Edited by wesnolte on 07-10-2009 01:51 AM
kaulsaksoftkaulsaksoft

Thanx Wes for looking into it.

 

No i dont I am not puttting the Id in the URL. I want to ask can the Extension controller get the data that is being entered in the VF Page ?

 

In my case currently i am get the null values from the fields and also it sometimes is unable to execute the calculate method. 

 

Pl guide me

wesnoltewesnolte

Yeah you can do that. But the object that the standard controller passes to your extension will be null unless you specify an Id. This is okay if you want to use this page to create records, I do the same in many places.

 

If you're going to use this page exclusively for creating new records change your constructor to read

 

 public CustomerFin(ApexPages.StandardController controller)
    {
     Cfc= new CustomerFinancialDetail__c();

   }

 

This way you'll have an empty object instead of a null value.

 

Cheers,

Wes

bsjbsj

Hello,

 

I am facing the same problem. What I want to do is that create a new record and link it to a parent record from which the user clicked 'New' in the detail page layout. My problem is how to obtain the master record id for which the user clicked New. I am getting null on calling stdcntrl.getrecord().

 

I have overridden the New button with a VF page with a std controller and an extension. I want to get the record id of the master record in the extension to get master record field values to create a record for the child object.

 

Any pointers welcome.

 

-bsj.