+ Start a Discussion
Rahul SharmaRahul Sharma 

Bug with integer field while using standard controller

Hello boards,

 

From last few days i ran into an issue, at start i thought its a issue with my application but later on realized its a behaviour of Integer field while using standard controller.

The example of what i'm trying to do is to display the fields in pageblocktable on click of a button using standard controller and extension.

Everything is working smoothly but only problem is with integer fields, even tough they contain null value it displays 0 in UI.

Below is small demo of the what i found:

 

Page:

<apex:page standardController="Account" extensions="stdAccCtrl">
<apex:form id="theForm">
<apex:pagemessages id="info"/>
<apex:inputText value="{!Account.NumberOfEmployees}"/>
<apex:commandButton action="{!Check}" value="Save" rerender="theForm"/>
</apex:form>
</apex:page>

 

 Extension:

public class stdAccCtrl {
    public Account objAccount {get;set;}
    public stdAccCtrl(ApexPages.StandardController controller){
        objAccount = (Account) controller.getRecord();
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Employees : '+String.valueOf(objAccount.NumberOfEmployees)));
    }
    public void Check(){
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Employees : '+String.valueOf(objAccount.NumberOfEmployees)));
    }
}

 I know its displaying 0 as a default for integer field but would like to know the reason in depth.

I would be happy is some one is able to shed some light on it.

Navatar_DbSupNavatar_DbSup

Hi,

 

You can try the below sample code with standard controller .if integer field NumberOfEmployees contains null or 0(zero) value when displaying the records in page block table it will display the blank instead of null or 0(zero).

 

<apex:page standardController="account" recordSetVar="account" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!account}" var="a">
<apex:column >
<apex:facet name="header"><b>Account Name</b></apex:facet>
{!a.name}
</apex:column>

<apex:column >
<apex:facet name="header"><b>Phone</b></apex:facet>
{!a.phone}
</apex:column>
<apex:column >
<apex:facet name="header"><b>Employees</b></apex:facet>
{!a.NumberOfEmployees}

</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 


 

 

Rahul SharmaRahul Sharma

Hi Navatar_DbSup,


I apppreciate your reply,

The problem is the field has no value(null) in it, In extensions controller i'm getting its value as null but in the function which is binded with command button i'm getting the value as 0.

Even the value is null in database but its displaying field value as zero after clicking the button.