0

I have an issue with rerending a selectoption value. I'm trying to retrieve the product img and the inventory level when I change the picklist value. But failed to do so. The picklist rerendering is important because it will rerender the img and inventory level for that particular product.

Am so stress trying to figure this out. Any help will be greatly appreciated. Thank you in advance!

VF PAGE:

  <apex:pageBlock title="Products" >
            <apex:pageBlockTable value="{!products}" var="item" id="s">


   <apex:column >
   <apex:image url="{!item.Image2}" id="img1"/>
   </apex:column>

            <apex:column headerValue="Product" value="{!item.Name}"/>

            <apex:column headerValue="Price" value="{!item.price}"/> 

             <apex:column headerValue="Color" >

          <Apex:actionRegion >
  <apex:selectList value="{!selColour}" multiselect="false" size="1"  >
                <apex:selectOptions value="{!Color}"/>  
                <apex:actionSupport event="onchange" action ="{!filter}" rerender="s"/>          

      </apex:selectList>  <br/>
      </Apex:actionRegion> 
     </apex:column>

             <apex:column headerValue="Quantity">
              <apex:inputText value="{!item.qtyToBuy}" rendered="{!(item.inStock)}"/>
              <apex:outputText value="Out of Stock" rendered="{! NOT(item.inStock)}"/>

            <apex:column >
 <apex:commandButton action="{!addToCart}" value="Add to Cart"/>
               </apex:column>
            </apex:pageblocktable>
        </apex:pageblock>

APEX CONTROLLER:

public class prod{
public void filter() {

 productList = new List<Product__c>();


  productList = [Select Name, ProductID__c, (SELECT ProductInventory__c.Colour__c FROM product__c.ProductInventorys__r WHERE ProductInventory__c.Colour__c = :selColour) From product__c WHERE ProductID__c = :prodID];

    for (Product__c l : productList){

    products.add(new DisplayProducts(l));
    }

}

}


    public class DisplayProducts {
        private Product__c products;

        public DisplayProducts(Product__c item) {
            this.products = item;
        }

         public DisplayProducts(Product__c item, Integer qty, String size, String col) {
            this.products = item;
            this.qtyToBuy = qty;
            this.size = size;
            this.color = col;
        }


        // Properties for use in the Visualforce view
        public String name {
            get { return products.Name; }
        }
        public String productid {
            get { return products.ProductID__c; }
        }
        public String description {
            get { return products.Description__c; }
        }

        public String color {


            get {
               List<ProductInventory__c> inventories = new List<ProductInventory__c>();
               List<String> colours = new List<String>();

               inventories = [Select ProductID__r.ProductID__c,Colour__c FROM ProductInventory__c 
                   WHERE ProductID__r.ProductID__c =:productid AND Colour__c =:color];

            for(ProductInventory__c invt :inventories){
                colours.add(invt.Colour__c);
            }
            return colours[0];
            } set;


        }

        public Decimal price {
            get { return products.Price__c; }
        }

        public String image2 {
            get {
            String img;
               List<ProductInventory__c> inventories = new List<ProductInventory__c>();
               List<String> colours = new List<String>();

               inventories = [Select ProductID__r.ProductID__c, Image2__c FROM ProductInventory__c 
                   WHERE ProductID__r.ProductID__c =:productid ];

            for(ProductInventory__c invt :inventories){
                colours.add(invt.Image2__c);
            }

             if(colours[0]!=null) 
            {
                Img= colours[0].substringBetween('src="' ,'"');
                Img.remove('amp;'); 
            }   
            return Img; }
            set;


        }


        public Boolean inStock {
            get { 

               List<ProductInventory__c> inventories = new List<ProductInventory__c>();
               List<Decimal> qty = new List<Decimal>();

               inventories = [Select ProductID__r.ProductID__c,Colour__c, Quantity__c, Image2__c,Image3__c,Image4__c, Size__c FROM ProductInventory__c 
                   WHERE ProductID__r.ProductID__c =:productid];


            for(ProductInventory__c invt :inventories){

                qty.add(invt.Quantity__c);

            }

            return  (0 < colours[0]);}}

        public Integer qtyToBuy { get; set; }
    }
1

Try to put an Id in apex:form id="main" and ReRender "main"

| improve this answer | |

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.