I am very new to VisualForce and Apex, and was hoping I can ask for help. I created a VF page, and a Custom Controller. All of the code is compiling and working as expected. I have created a list in the VF page, that will update when a Filter button is selected. What I am trying to accomplish is to default the list to have a default list of records, before the button is selected. Once it is selected, the filters should take affect and overwrite the list. I thought I could accomplish that by defining my PageBlockTable {!getStoryTasks }
to have 2 values, but I do not think that would work. So not really sure how I can approach this.
VF Page
<apex:PageBlock title="Current Sprint" id="current_sprint">
<apex:pageBlockTable value="{! getCurrentSprint }" var="cs">
<apex:column value="{!cs.id }"/>
<apex:column value="{!cs.Name }"/>
<apex:column value="{!cs.Start_Date__c }"/>
<apex:column value="{!cs.End_Date__c }"/>
<apex:column value="{!cs.Story_Points__c }"/>
<apex:column value="{!cs.Velocity__c }"/>
</apex:pageBlockTable>
</apex:PageBlock>
<apex:form >
<apex:pageBlock title="Story Tasks" id="story_tasks">
<apex:pageBlockSection title="Filters" columns="1">
Current Sprint: {target_date} <br/>
<apex:inputField value="{!stt.Owner__c}"/>
<!-- <apex:inputField value="{!stt.Story__c}"/> -->
<apex:inputField value="{!s.Sprint__c}"/>
<apex:commandButton action="{!filterStoryTask }" value="FILTER" />
</apex:pageBlockSection>
<!--Story Task List -->
<apex:PageBlockTable value="{! getStoryTasks }" var="st">
<apex:column value="{! st.Name }"/>
<apex:column value="{! st.Subject__c }"/>
<apex:column value="{! st.Owner__c }"/>
<apex:column value="{! st.Story__c }"/>
<apex:column value="{! st.Story__r.Sprint__r.Name }"/>
</apex:PageBlockTable>
</apex:pageBlock>
</apex:form>
Controller
public with Sharing class SprintTasksCon{
private String sortOrder = 'Name';
public Story__c s { get;set; }
public Sprint__c sp { get;set; }
public Story_Task__c stt { get;set; }
Date target_date = Date.today();
public List <Story_Task__c> getStoryTasks{get;set;}
public List <Sprint__c> getCurrentSprint{get;set;}
public void filterStoryTask(){
getStoryTasks = new List<Story_Task__c>();
if(stt.Owner__c !=null && s.Sprint__c!=null){
getStoryTasks = [Select Id, Name, Owner__r.Name, Story__r.Name, Subject__c, Story__r.Sprint__r.Name
FROM Story_Task__c
WHERE Owner__c=:stt.Owner__c AND Story__r.Sprint__c=:s.Sprint__c Limit 100];
}
else if(s.Sprint__c == null){
getStoryTasks = [Select Id, Name, Owner__r.Name, Story__r.Name, Subject__c, Story__r.Sprint__r.Name
FROM Story_Task__c
WHERE Owner__c=:stt.Owner__c Limit 100];
}
else if(stt.Owner__c == null){
getStoryTasks = [Select Id, Name, Owner__r.Name, Story__r.Name, Subject__c, Story__r.Sprint__r.Name
FROM Story_Task__c
WHERE Story__r.Sprint__c=:s.Sprint__c Limit 100];
}
else{
getStoryTasks = [Select Id, Name, Owner__r.Name, Story__r.Name, Subject__c, Story__r.Sprint__r.Name
FROM Story_Task__c Limit 100];
}
}
public SprintTasksCon(){
stt = new Story_Task__c();
s = new Story__c();
getCurrentSprint = [Select Id, Name, Start_Date__c, End_Date__c, Story_Points__c, Velocity__c
FROM Sprint__c target_date
WHERE Start_Date__c <: target_date AND End_Date__c >: target_date Limit 1];
}
}