3

Controller:

public with sharing class ControllerExtension {
   public Set<WrapperOppLineItem> shoppingCartSet {
        get;
        set;
   }

    public class WrapperOppLineItem{
        public opportunityLineItem oppLineitem {get;set;}
        public Boolean selected {get;set;}
        public Id idValue {get;set;}

        public WrapperShoppingCart(opportunityLineItem oLineItem ){
            oppLineitem = oLineItem;
            selected = false;
            idValue = oLineItem.id;
        }

        public Boolean equals(Object obj){
            if(obj!= null && obj instanceOf OpportunityLineItem){
                OpportunityLineItem li = (OpportunityLineItem) obj;
                if((li.id == idValue)){
                    return true;
                }else{
                    return false;
                }
            }else{
                return false;
            }
        }

    }
}

Visualforce:

            <apex:pageblockTable value="{!shoppingCartSet}" var="s">
                    <apex:column >
                        <apex:inputCheckbox value="{!s.selected}"/>                     
                    </apex:column>
            </apex:pageblockTable

It throws error saying that 'Unknown Property SetValue.selected'

Note: I did not include the complete code for controller and visualforce but just the relevant part to show the problem I have.

2

It looks like the collection cannot be a Set in this Visualforce context. You can add a property that converts it into a List:

public List<WrapperOppLineItem> shoppingCartList {
    get {
        return new List<WrapperOppLineItem>(shoppingCartSet);
    }
}

and reference that shoppingCartList instead; that list will be referencing the same underlying WrapperOppLineItem objects.

You should also add a hashCode method to your WrapperOppLineItem if you haven't already. See e.g. Using Custom Types in Map Keys and Sets. There is a static System.hashCode method you can use on any type object including the Id type, so based on your equals, the method would be at its simplest:

public Integer hashCode() {
    return System.hashCode(idValue);
}

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.