0

I am trying to build a sell sheet which comes in two VF pages. In the first page the products will be displayed based on the category selected. The products are shown in an apex:repeat. There is a checkbox next to each product. I am looking for a way to pass the name/id of the selected products (by checkbox selection) to a set in the controller in a way that the name/id gets added to set each time the user turns on the checkbox. Once the user selects the required products, a save button redirects to another page where its shows only the products that were selected in the first page. I was able to get the products based on category, but stuck in the logic of how to access (and pass to controller) the row/item details when a checkbox next to the row/item is selected.

I am totally stuck in this. Hope anyone can help me in this.

VF Page

<apex:page standardController="Private_Label__c" extensions="privateLabelSellSheetCustomizer" lightningStylesheets="true">
  <script type="text/javascript">
    function fireFieldsLoader(id) {
      var type = document.getElementById(id).value;
      check(type);
      alert(type);
      //return true;
    }
  </script>
   <apex:form>
    <apex:actionFunction name="check" action="{!loadProducts}" reRender="productList">
      <apex:param name="plSelectedCategory" value="" />
    </apex:actionFunction>
    <apex:actionFunction name="add" action="{!addProduct}" reRender="productList">
      <apex:param name="plSelectedProduct" value="" />
    </apex:actionFunction>
    <apex:pageBlock>
      <apex:pageBlockSection columns="1">
        <apex:inputField id="check" value="{!Private_Label__c.Category__c}" onchange="fireFieldsLoader('{!$Component.check}');" label="Select Category"
        />
        
      </apex:pageBlockSection>
      <apex:pageBlockSection>

        <apex:outputPanel id="productList">
          <apex:outputText value="Selected Products:{!pselect}" />
          <div class="collection">
            <apex:repeat value="{!plabelGridViewList}" var="plabel">
              <div class="product">
                <div class="pimage">
                  <apex:selectCheckboxes id="add" value="{!plabel.Name}" onclick="fireFieldsLoader('{!$Component.add}');"/>
                  <apex:outputField value="{!plabel.Product_Image__c}"></apex:outputField>
                </div>

                <div class="pname">
                  <apex:outputText value="{!plabel.Name}"></apex:outputText>
                </div>
              </div>
            </apex:repeat>
          </div>
        </apex:outputPanel>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

Controller

public inherited sharing class privateLabelSellSheetCustomizer {
    public string plCategory {get;set;}
    public string plProduct {get;set;}
    private final Private_Label__c pLabel;
    public List<Integer> indexes{get;set;}
    public List<Private_Label__c> pl{get;set;}
    public List<Private_Label__c> plabelGridViewList {get;set;}
    public set<String> selectedProducts{get;set;}
    public privateLabelSellSheetCustomizer() {

    }
    public privateLabelSellSheetCustomizer(ApexPages.StandardController stdController) {
        this.pLabel = (Private_Label__c)stdController.getRecord();
    }
    public pageReference loadProducts(){
        plCategory = apexpages.currentPage().getParameters().get('plSelectedCategory');
        plabelGridViewList = new List<Private_Label__c>();
        pl=[SELECT Name, Product_Image__c FROM Private_Label__c WHERE Category__c LIKE: plCategory];
        this.indexes = new List<Integer>();
        for(Integer i=0;i<pl.size();i++)
        {
            this.indexes.add(i);
        }
        for (Private_Label__c plabelgrid: pl){
            plabelGridViewList.add(plabelgrid);
        }
        return null;
    }

    public Pagereference addProduct(){
        plProduct = apexpages.currentPage().getParameters().get('plSelectedProduct');
        selectedProducts.add(plProduct);
        return null;
    }
}
1
  • you need a wrapper class in the controller and the apex:repeat iterates on the list of wrappers. – cropredy Feb 16 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.