function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VempallyVempally 

not able to display selected list values into data table of VF

Iam trying to display the selected list of records into the data table. there is no error invoked but still the data is not visible...
here is the code

<apex:page standardController="Product__c" extensions="prosearch">
  <apex:form >
  <apex:pageblock >
   <apex:pageBlockSection >
  
   <apex:pageBlockSectionItem >
   <apex:outputLabel >Select Department</apex:outputLabel>
      <apex:selectList value="{!selecteddept}" size="1">
           <apex:selectOptions value="{!deptitems}" rendered="true" />
      </apex:selectList>
   </apex:pageBlockSectionItem>
        <apex:commandButton id="search" Value="search" action="{!search}"/>

  
    <apex:outputPanel >
    <apex:outputtext value="{!selecteddept}"></apex:outputtext>
      <apex:datatable value="{!searchlist}" var="a" id="theTable" title="Iam HERE" >

            <apex:facet name="retrieved">We Have The Following Products</apex:facet>
       
       <apex:column >
            <apex:facet name="ProductName">Product Name</apex:facet>
            
            <apex:outputtext value="{!a.Product_Name__c}"/>
        </apex:column>
      
        <apex:column >
            <apex:facet name="ProductPrice">Product Price</apex:facet>
            <apex:outputText value="{!a.Price__c}"/>
        </apex:column>
      </apex:datatable>

    </apex:outputPanel>
   </apex:pageBlockSection>
 
  </apex:pageBlock>
 
  </apex:form>
</apex:page>


here is the apex code

public with sharing class prosearch {

    public prosearch(ApexPages.StandardController controller) {
     
    }
    public List<Product__c> searchlist{set; get;}
    public string selectedDept{set;get;}
    public string productname{ set; get;}
    public decimal productprice{ set;get;}
    public  string productimage{ set;get;}
    
    public string getselectedDept(){
      
       return selecteddept;
       
       }
        public void setselecteddept() {
           this.selecteddept = selecteddept;
    }
   public string deptItems{set; }

   public List<SelectOption> getdeptItems() {
            List<SelectOption> options = new List<SelectOption>();
             Schema.DescribeFieldResult fieldResult =Product__c.Product_department__c.getDescribe();   
        List<Schema.picklistEntry> ple = fieldResult.getPicklistValues();
          for(Schema.picklistEntry f:ple)   
        {   
            options.add(new selectOption(f.getLabel(),f.getValue()));                   
        }   
        return Options;
       
       
}


    public pagereference search(){
      return null;
      }
 
public List<Product__c> searchproduct(){


List<Product__c> searchlist = new List<Product__c>();
        searchlist = [select Product_Name__c,Price__c,Product_Image__c from Product__C where product_department__C =: selecteddept];
  
     return searchlist; 
     
 

    
 

}
}
Best Answer chosen by Vempally
SFDC_DevloperSFDC_Devloper
Hi Suresh...

 call controller method in your VF page...
<apex:page standardController="Product__c" extensions="prosearch">
  <apex:form >
  <apex:pageblock >
   <apex:pageBlockSection >
  
   <apex:pageBlockSectionItem >
   <apex:outputLabel >Select Department</apex:outputLabel>
      <apex:selectList value="{!selecteddept}" size="1">
           <apex:selectOptions value="{!deptitems}" rendered="true" />
      </apex:selectList>
   </apex:pageBlockSectionItem>
        <apex:commandButton id="search" Value="search" action="{!search}"/>

  
    <apex:outputPanel >
    <apex:outputtext value="{!selecteddept}"></apex:outputtext>
      <apex:datatable value="{!searchproduct}" var="a" id="theTable" title="Iam HERE" >

            <apex:facet name="retrieved">We Have The Following Products</apex:facet>
       
       <apex:column >
            <apex:facet name="ProductName">Product Name</apex:facet>
            
            <apex:outputtext value="{!a.Product_Name__c}"/>
        </apex:column>
      
        <apex:column >
            <apex:facet name="ProductPrice">Product Price</apex:facet>
            <apex:outputText value="{!a.Price__c}"/>
        </apex:column>
      </apex:datatable>
    </apex:outputPanel>
   </apex:pageBlockSection>
 
  </apex:pageBlock>
 
  </apex:form>
</apex:page>

Thanks,
Rockzz

All Answers

SFDC_DevloperSFDC_Devloper
Hi,

try below code...

public with sharing class prosearch {

    public prosearch(ApexPages.StandardController controller) {
     
    }
    public List<Product__c> searchlist{set; get;}
    public string selectedDept{set;get;}
    public string productname{ set; get;}
    public decimal productprice{ set;get;}
    public  string productimage{ set;get;}
    
    public string getselectedDept(){
      
       return selecteddept;
       
       }
        public void setselecteddept() {
           this.selecteddept = selecteddept;
    }
   public string deptItems{set; }

   public List<SelectOption> getdeptItems() {
            List<SelectOption> options = new List<SelectOption>();
             Schema.DescribeFieldResult fieldResult =Product__c.Product_department__c.getDescribe();   
        List<Schema.picklistEntry> ple = fieldResult.getPicklistValues();
          for(Schema.picklistEntry f:ple)   
        {   
            options.add(new selectOption(f.getLabel(),f.getValue()));                   
        }   
        return Options;
       
       
}


    public pagereference search(){
      return null;
      }
 
public List<Product__c> searchproduct(){


        searchlist = [select Product_Name__c,Price__c,Product_Image__c from Product__C limit 10];
  
     return searchlist; 
     
 
    
 

}
}

Thanks,
Rockzz

VempallyVempally
Hi Rcokzz

thanks for your respone...

but the searchlist should contain the products based on the department selected.
In such a case we cannot avoid the where clause...
SFDC_DevloperSFDC_Devloper
Hi Suresh...

 call controller method in your VF page...
<apex:page standardController="Product__c" extensions="prosearch">
  <apex:form >
  <apex:pageblock >
   <apex:pageBlockSection >
  
   <apex:pageBlockSectionItem >
   <apex:outputLabel >Select Department</apex:outputLabel>
      <apex:selectList value="{!selecteddept}" size="1">
           <apex:selectOptions value="{!deptitems}" rendered="true" />
      </apex:selectList>
   </apex:pageBlockSectionItem>
        <apex:commandButton id="search" Value="search" action="{!search}"/>

  
    <apex:outputPanel >
    <apex:outputtext value="{!selecteddept}"></apex:outputtext>
      <apex:datatable value="{!searchproduct}" var="a" id="theTable" title="Iam HERE" >

            <apex:facet name="retrieved">We Have The Following Products</apex:facet>
       
       <apex:column >
            <apex:facet name="ProductName">Product Name</apex:facet>
            
            <apex:outputtext value="{!a.Product_Name__c}"/>
        </apex:column>
      
        <apex:column >
            <apex:facet name="ProductPrice">Product Price</apex:facet>
            <apex:outputText value="{!a.Price__c}"/>
        </apex:column>
      </apex:datatable>
    </apex:outputPanel>
   </apex:pageBlockSection>
 
  </apex:pageBlock>
 
  </apex:form>
</apex:page>

Thanks,
Rockzz
This was selected as the best answer
VempallyVempally
IT WORKED,
THANKS A LOT......