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
chokchok 

need help to write a custom controller to display data in VF pageblock table

 

Hi,

i am new to apex , please help me

 

here is my VF code:

 

<apex:page controller="titlesalary">
<apex:form >
<apex:sectionHeader title="designation"/>
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!save}" value="submit"/>
</apex:pageBlockButtons>

title<apex:selectlist value="{!title}" size="1">
<apex:selectOption itemValue="none" itemLabel="--None--"/>
<apex:selectOption itemValue="developer" itemLabel="developer"/>
<apex:selectOption itemValue="sr.developer" itemLabel="sr.developer"/>
<apex:selectOption itemValue="admin" itemLabel="admin"/>
</apex:selectList>
year<apex:selectlist value="{!year}" size="1">
<apex:selectOption itemValue="none" itemLabel="--None--"/>
<apex:selectOption itemValue="2009" itemLabel="2009"/>
<apex:selectOption itemValue="2010" itemLabel="2010"/>
<apex:selectOption itemValue="2011" itemLabel="2011"/>
</apex:selectList>
department<apex:selectList value="{!department}" size="1">
<apex:selectOption itemValue="none" itemLabel="--None--"/>
<apex:selectOption itemValue="it" itemLabel="IT"/>
<apex:selectOption itemValue="engg" itemLabel="ENGG"/>
<apex:selectOption itemValue="service" itemLabel="SERVICE"/>
</apex:selectList>
<apex:pageBlockTable value="{!salary}" var="hi" columns="4">
<apex:column headervalue="title" value="{!title}"/>
<apex:column headervalue="year" value="{!year}"/>
<apex:column headervalue="department" value="{!department}"/>
<apex:column headervalue="salary" value="{!salary}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

I am using custom controller.my task is  to display yearly salary according to job title in VF PAGE BLOCK table.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I reckon you'll need a controller something like:

 

 

public class SalaryController
{
   public String title {get; set;}
   public String year {get; set;}
   public String department {get; set;}
   public List<Salary__c> salary {get; set;}

   public SalaryController()
   {
      salary=new List<Salary__c>();
   }

   public PageReference save()
   {
      salary=[select title, year, department, salary 
                from Salary__c 
                where title=:title
                and   department=:department
                and   year=:year];
   }
}

 There are three properties backing your select list and I've assumed the save button executes the search.

 

Note that this won't handle if the user selects 'none' - the where clause would need to be built dynamically to include/exclude the selected options.

 

All Answers

bob_buzzardbob_buzzard

So have you had a stab at the controller and had problems or are you starting from scratch?

chokchok

Hi Bob,

 

I am starting from scratch.

 

please guide me.

 

thanks

bob_buzzardbob_buzzard

You'll need to tell us a little more about the sobjects that are backing the page.  For example, are the properties that are backing the selectlist from an sobject or are they at the controller level?

chokchok

i think its controller level, i inserted data from custom object and now i want to display yearly/department salary in pageblock table

bob_buzzardbob_buzzard

I reckon you'll need a controller something like:

 

 

public class SalaryController
{
   public String title {get; set;}
   public String year {get; set;}
   public String department {get; set;}
   public List<Salary__c> salary {get; set;}

   public SalaryController()
   {
      salary=new List<Salary__c>();
   }

   public PageReference save()
   {
      salary=[select title, year, department, salary 
                from Salary__c 
                where title=:title
                and   department=:department
                and   year=:year];
   }
}

 There are three properties backing your select list and I've assumed the save button executes the search.

 

Note that this won't handle if the user selects 'none' - the where clause would need to be built dynamically to include/exclude the selected options.

 

This was selected as the best answer
chokchok

Thanks Bob,it works perfect