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
SFmaverickSFmaverick 

Script / code / logic to rerender a list without a user action

I have a page that intially will look like this that asks the user for a date:

 

 

After the user enters a date, the page generates a a table with 7 nested tables (one per column) that each pull from a list. Here's an example with user input.

 

 

The issue I'm having is that I can only get it to increment one day. Each column should go to the next day, but I can't wrap my head around why it's not doing that and how I can make it do that, without creating a seperate List method for each column and a seperate method for incrementing as well. The lists are selected based off of the date the user enters. The first column is all the records from the date they entered. The second column is all the records from the day they entered + 1. Ideally this trend will continue without making the code and hence the processing 7 times the labor. I know it can be done more simply, but I'm not familiar enough with Java and Apex to wrap my head around it. Any help is appreciated, my current code is below.

 

 

<apex:page showHeader="false" standardStyleSheets="false" controller="ScheduleViewController">
  <apex:form >
    <strong>Please enter the first day of the schedule you would like to see (mm/dd/yyyy):</strong> <apex:inputText value="{!BegDate}"/> 
  </apex:form>

  <apex:outputPanel >
    <table border="0" bordcolor="00000" cellspacing="0" width="80%" bgcolor ="#000000"> <!-- Table that contains 7 day of weektables -->
        <tr>
        <td>
        <apex:dataList value="{!TheList}" var="item"> <!-- Gets the list of shifts -->
        <table border="1" bordercolor="00000" width="100%" bgcolor="00000">
            <tr>
            <td bgcolor="#30C452">{!item.Shift_Summary__c}
            <br></br>{!item.Shift_Summary_2__c}
            <br></br>{!item.Shift_Summary_3__c}
            <br></br>{!item.Day_of_week__c}</td>
            </tr>
        </table>
        </apex:dataList>
        </td>
        <apex:outputpanel id="Day2">
        <td>
        <apex:dataList value="{!TheList2}" var="item"> <!-- Gets the list of shifts -->
        <table border="1" bordercolor="00000" width="100%" bgcolor="00000">
            <tr>
            <td bgcolor="#30C452">{!item.Shift_Summary__c}
            <br></br>{!item.Shift_Summary_2__c}
            <br></br>{!item.Shift_Summary_3__c}
            <br></br>{!item.Day_of_week__c}</td>
            </tr>
        </table>
        </apex:dataList>
        </td>
        </apex:outputpanel>
        
        <td>
        <apex:dataList value="{!TheList2}" var="item"> <!-- Gets the list of shifts -->
        <table border="1" bordercolor="00000" width="100%" bgcolor="00000">
            <tr>
            <td bgcolor="#30C452">{!item.Shift_Summary__c}
            <br></br>{!item.Shift_Summary_2__c}
            <br></br>{!item.Shift_Summary_3__c}
            <br></br>{!item.Day_of_week__c}</td>
            </tr>
        </table>
        </apex:dataList>
        </td>
        
        <td>
        <apex:dataList value="{!TheList2}" var="item"> <!-- Gets the list of shifts -->
        <table border="1" bordercolor="00000" width="100%" bgcolor="00000">
            <tr>
            <td bgcolor="#30C452">{!item.Shift_Summary__c}
            <br></br>{!item.Shift_Summary_2__c}
            <br></br>{!item.Shift_Summary_3__c}
            <br></br>{!item.Day_of_week__c}</td>
            </tr>
        </table>
        </apex:dataList>
        </td>
        
        <td>
        <apex:dataList value="{!TheList2}" var="item"> <!-- Gets the list of shifts -->
        <table border="1" bordercolor="00000" width="100%" bgcolor="00000">
            <tr>
            <td bgcolor="#30C452">{!item.Shift_Summary__c}
            <br></br>{!item.Shift_Summary_2__c}
            <br></br>{!item.Shift_Summary_3__c}
            <br></br>{!item.Day_of_week__c}</td>
            </tr>
        </table>
        </apex:dataList>
        </td>
        
        <td>
        <apex:dataList value="{!TheList2}" var="item"> <!-- Gets the list of shifts -->
        <table border="1" bordercolor="00000" width="100%" bgcolor="00000">
            <tr>
            <td bgcolor="#30C452">{!item.Shift_Summary__c}
            <br></br>{!item.Shift_Summary_2__c}
            <br></br>{!item.Shift_Summary_3__c}
            <br></br>{!item.Day_of_week__c}</td>
            </tr>
        </table>
        </apex:dataList>
        </td>
        
        <td>
        <apex:dataList value="{!TheList2}" var="item"> <!-- Gets the list of shifts -->
        <table border="1" bordercolor="00000" width="100%" bgcolor="00000">
            <tr>
            <td bgcolor="#30C452">{!item.Shift_Summary__c}
            <br></br>{!item.Shift_Summary_2__c}
            <br></br>{!item.Shift_Summary_3__c}
            <br></br>{!item.Day_of_week__c}</td>
            </tr>
        </table>
        </apex:dataList>
        </td>
        </tr>
    </table>
  </apex:outputPanel>
</apex:page>

 

public class ScheduleViewController {

    //Initializes and provides a get method for the user inputted date
    public String BegDate { get; set; }

    public Date DayDate;
    // Turns the User's string input into a date
    public Date getDayDate(){
        if (BegDate==null) {
            return null;
        } else {
            DayDate = stringToDate(BegDate);
            return DayDate;
        }
    }
    
    public Date IncrementDayDate(){
        if (DayDate!=null) {
            DayDate = DayDate + 1;
        }
        return DayDate;
    }

    
    //Converts a string from mm/dd/yy to a date
    public Date stringToDate(String s){
      //Input Date String is in the format mm/dd/yyyy
      if(s.length()== 0)
      {
      return NULL;
      }
      else{
      String[] stringDate = s.split('/');
      Integer m =  Integer.valueOf(stringDate[0]);
      Integer d = Integer.valueOf(stringDate[1]);
      Integer y = Integer.valueOf(stringDate[2]);
      return date.newInstance(y,m,d);
      }
    }
    
    //Gets TheList - an array of records from Shift__c where the Date equals DayDate
    public List<Shift__c> getTheList() {
        Date theDate=getDayDate();
        List<Shift__c> TheList = [SELECT Shift_Summary__c, Shift_Summary_2__c, Shift_Summary_3__c, Day_of_week__c, Date__c FROM Shift__c WHERE Date__c = :DayDate];
        System.Debug('MY LIST:' + TheList);
        System.Debug('DayDate:' + DayDate);
        return TheList;
    }
    
    public List<Shift__c> getTheList2() {
        Date NewDate = IncrementDayDate();
        List<Shift__c> TheList2 = [SELECT Shift_Summary__c, Shift_Summary_2__c, Shift_Summary_3__c, Day_of_week__c, Date__c FROM Shift__c WHERE Date__c = :NewDate];
        return TheList2;
    }
}