+ Start a Discussion
Tyler HarrisTyler Harris 

Unknown Property Error on Visualforce Page

I'm trying to display a simple counter on my visualforce page that counts the number of shopping cart items.

Error: Unknown Property: "StoreFront.shopCart"

Apex:
 
public class StoreFrontController{

    list<DisplayMerchandise> products;     	
     
    integer shopCart;
    
    public list<DisplayMerchandise> getProducts(){
        if(products == null){
            products = new List<DisplayMerchandise>();
           
            for (Merchandise__c item : [SELECT Id, Name, Description__c, Price__c, Total_Inventory__c FROM Merchandise__c]) {
            	products.add(new DisplayMerchandise(item));
           
                
            }
                

            
        }         
       return products; 
    }
    
    public Integer getshopCart(){
        
        return shopcart;
    }
 
<apex:page standardStylesheets="false" showHeader="false" sidebar="false" controller="StoreFront">
  <apex:stylesheet value="{!URLFOR($Resource.styles)}"/>
  <h1>Store Front</h1>
  
  <apex:form >
      <apex:dataTable value="{!products}" var="pitem" rowClasses="odd,even">
          <apex:column headerValue="Product">
              <apex:outputText value="{!pitem.merchandise.name}" />
          </apex:column>
          <apex:column headervalue="Price">
              <apex:outputText value="{!pitem.merchandise.Price__c}" />
          </apex:column>
          <apex:column headerValue="#Items">
              <apex:inputText value="{!pitem.count}"/>
          </apex:column>
   
      </apex:dataTable>
      <br/>
      <apex:commandButton action="{!shop}" value="buy" reRender="msg" />
  </apex:form>
  
  <apex:outputPanel id="msg">{!message}</apex:outputPanel>

<apex:form>
    <apex:dataTable value="{!shopCart}" var='sq' rowClasses="odd,even">
    <apex:column>
    
        <apex:outputField value='{!sq.count}' />
        
    </apex:column>
    </apex:dataTable>
</apex:form>
  
  
  
  
</apex:page>

 
Leslie  KismartoniLeslie Kismartoni
You need to initialize the variable shopcart somewhere... 

Add this constructor?
 
public StoreFrontController() {
shopcart = 0;
}

 
Tyler HarrisTyler Harris
Thanks Leslie. I tried that but it didn't work. I added that argument as an inner class
 
public class StoreFrontController{

    list<DisplayMerchandise> products;     	
     
    public integer shopCart;
 
    
    public list<DisplayMerchandise> getProducts(){
        if(products == null){
            products = new List<DisplayMerchandise>();
            
           
            for (Merchandise__c item : [SELECT Id, Name, Description__c, Price__c, Total_Inventory__c FROM Merchandise__c]) {
            	products.add(new DisplayMerchandise(item));
           
                
            }
                

            
        }         
       return products; 
    }
    
    public StoreFrontController() {
shopcart = 0;
}
    
    public Integer getshopCart(){
        
        return shopCart;
    }

    List<DisplayMerchandise> shoppingCart = new List<DisplayMerchandise>();
    


    public PageReference addToCart(){
    
        for(DisplayMerchandise p : products){
        if(0 < p.qtyToBuy){

            shoppingCart.add(p);
            shopCart++;
            }
        
                
        }
    return null;
    }
    
    public String getCartContents() {
        if(0 == shoppingCart.size()) {
        return '(empty)';
        }
        
        
        String msg = '<ul>\n';
        for(DisplayMerchandise p : shoppingCart){
        msg += '<li>';
        msg += p.name  + '(' + p.qtyToBuy + ')';
        msg += '</li>\n';
        
        }
        msg += '</ul>';
        return msg;
    
    }
    


public class DisplayMerchandise{

private Merchandise__c merchandise;
public DisplayMerchandise(Merchandise__c item){

this.merchandise = item;

}

public String name {

get{return merchandise.Name;}

}

    
public String description{

get {return merchandise.Description__c;}

}

public Decimal price {

get{return merchandise.Price__c;}

}

public Boolean inStock{

get{return(0 < merchandise.Total_Inventory__c);}

}

public Integer qtyToBuy{get;set;}

}


}

 
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Tyler Harris,

Check you controller name on your page,
<apex:page standardStylesheets="false" showHeader="false" sidebar="false" controller="StoreFront">

Change it to 
<apex:page standardStylesheets="false" showHeader="false" sidebar="false" controller="StoreFrontController">
Let us know if it helps you.


 
Tyler HarrisTyler Harris
Yes thank you for that. What I'm trying to is create a shoppingCart object that mirrors the products put in the cart. I basically want a counter that counts the product amount entered in the Visualforce page.

I cannot get my "shopCart" object to display on the page without a "Unknown property 'StoreFront.shopCart.count'
Error is in expression '{!shopCart.count}' in component <apex:outputText> in page storefront"

Visualforce
<apex:page standardStylesheets="false" showHeader="false" sidebar="false" controller="StoreFront">
  <apex:stylesheet value="{!URLFOR($Resource.styles)}"/>
  <h1>Store Front</h1>
  
  <apex:form >
      <apex:dataTable value="{!products}" var="pitem" rowClasses="odd,even">
          
          <apex:column headerValue="Product">
              <apex:outputText value="{!pitem.merchandise.name}" />
          </apex:column>
          <apex:column headervalue="Price">
              <apex:outputText value="{!pitem.merchandise.Price__c}" />
          </apex:column>
          <apex:column headerValue="#Items">
              <apex:inputText value="{!pitem.count}"/>
          </apex:column>
   
      </apex:dataTable>
      
      <br/>
      <apex:commandButton action="{!shop}" value="buy" reRender="msg" />
  </apex:form>
  
  <apex:outputPanel id="msg">{!message}</apex:outputPanel>    
 
    <apex:outputText >{!shopCart.count}</apex:outputText>
  
</apex:page>

Apex
public class StoreFront {

    public String message { get; set; }
    
   
    
    
    public PageReference shop(){
    message = 'You bought: ';
        for (DisplayMerchandise p:products){
            if(p.count > 0){
               message += p.merchandise.name + ' (' + p.count + ') ' ;
            }
        }
        return null;
    }
    
    DisplayMerchandise[] products;
    shopCart shoppie;

    public class shopCart{
        public integer count=0;
        public shopCart(Integer item){
            this.count = item;
                }
        
    }
    
    public shopCart getShopCart(){
        if(!products.isEmpty()){
            shoppie.count = products.size();
            
        }
        return shoppie;
    }
    
    
        public class DisplayMerchandise {
        public Merchandise__c merchandise{get; set;}
        public Decimal count{get; set;}
        public DisplayMerchandise(Merchandise__c item){
            this.merchandise = item;
        }
       }
    
    public DisplayMerchandise[] getProducts() {
        
        if (products == null){
            products = new DisplayMerchandise[]{};
            for (Merchandise__c item : 
            [SELECT id, name, description__c, price__c
            FROM Merchandise__c
            WHERE Total_Inventory__c > 0]) {
            
            products.add(new DisplayMerchandise(item));
         	
            }
    
    }
        
    return products;
    }

}


 
nansi kela 21nansi kela 21

Hi  Tyler Harris..

Do U get any solution regarding it..???
I also need this kind of Fucntionaly .. if u get any solution Then please share it..

Thank you
Regards,
Nansi Kela