0

I created Apex class with static field. I would like to use it as a value in on my custom visualforce page. On that page I use my custom controller as well. How can i access this field?

<apex:outputText value="{!Company.total_amount__c}" />

This piece of code is not allowed because it doesn't understand total_amount__c field which is defined in Company class, not controller.

Thanks in advance

EDIT:

My class with static field:

public class Company{

    public String name = 'BazuBazu';
    public static Decimal total_amount = 6;


}

My controller class:

public class opportunityList2Con {

public Decimal total_amount { get; set; }


    public Decimal getTotalAmount(){
        return Company.total_amount;
     }
}

My custom page:

<apex:page controller="opportunityList2Con">
<apex:form >
    <apex:pageBlock >

            <apex:pageBlockTable value="{!employees}" var="o" >

            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.Email__c}"/>
            <apex:column value="{!o.Annual_salary__c}"/>

            </apex:pageBlockTable>
    </apex:pageBlock>
    <apex:commandButton action="{!view}" value="View" id="theViewButton" />
    <apex:commandButton action="{!edit}" value="Edit" id="theEditButton"/>
    <apex:outputLabel >Total amount of bill </apex:outputLabel>
    <apex:outputText value="{!total_amount}" />


</apex:form>

</apex:page

The field's value doens't display on a page

4
  • 1
    You can create a method in the controller class which accesses the value from the static property of your other class and returns it to the page.
    – Doug B
    Commented Oct 8, 2015 at 16:37
  • @DougB nice idea, thanks for that. unfortunately i've got such error: Compile Error: Initial term of field expression must be a concrete SObject:String
    – k4sia
    Commented Oct 8, 2015 at 16:41
  • The technique will work, so share your code as there must be a problem in how you are doing that
    – Doug B
    Commented Oct 8, 2015 at 16:47
  • @DougB code added
    – k4sia
    Commented Oct 8, 2015 at 16:51

1 Answer 1

1

Remove

public Decimal total_amount { get; set; } and

set your VF field to {!totalAmount}

<apex:outputText value="{!totalAmount}" />

You must log in to answer this question.

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