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 

Call to controller to increment a variable

Basically throughout my visualforce page, I'd like to take a variable that's been set, and I'd like to increment it by 1 several different times. I'm sure there's an easy way to make a call like this that I'm just not considering. Here's the current code:

 

Page Code - It's simply taking in a text value called BegDate and outputting a Date value called DayDate

 

 

<apex:page showHeader="false" standardStyleSheets="false" controller="TestViewController">
  <apex:form >
    <apex:inputText value="{!BegDate}"/>
    
    <apex:outputText value="{!DayDate}"/>
    
    <!-- This is where I'd like to output DayDate a second time, but incremented by 1>
    <apex:outputText value="{!DayDate}"/>
  </apex:form>
</apex:page>

 

Controller Code: It's taking the user input and converting it from text to a date format. I'd like to somehow make call to the controller from the visualforce page to increment DayDate by 1.

 

 

public class TestViewController {

    public String BegDate { get; set; }

    // Turns the User's string input into a date
    public Date getDayDate(){
        if (BegDate==null) {
            return null;
        } else {
            return stringToDate(BegDate);
        }
    }
    
    //Converts a string from mm/dd/yyyy 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);
      }
    }
}

 

 

 

hisrinuhisrinu

You can make use of actionpoller tag to call an function from controller recursively

SFmaverickSFmaverick

I don't want to increment based on time: I want to tell it when to increment. I need it to increment at 6 different points, all before the page is rendered and displayed.

SargeSarge

Hi,

 

   If it is exactly six different places where you need to place this date increemented, you can create an inner class having six variables each of which is increemented by one day. Then refere to the variables of instance of this inner class.

SFmaverickSFmaverick

Assuming I did create a class that had this Date incremented six different times; that would also require that I had 6 seperate constructors for my list each called with a different variable to filter by date. I don't think that's an easy solution, it's going to make the code much longer and harder to maintain.

SargeSarge

Hi,

 

      I think you misunderstood me/ you are not posting all of whatever you want. Let me repost your code with modifications

 

 

<apex:page showHeader="false" standardStyleSheets="false" controller="TestViewController">
  <apex:form >
    <apex:inputText value="{!BegDate}"/>
    
   <!--FirstTime-->
 <apex:outputText value="{!bDates.dayDate1}"/> <!-- This is where I'd like to output DayDate a second time, but incremented by 1> <apex:outputText value="{!bDates.dayDate2}"/> // and so on till bDates.dayDate6
 </apex:form> </apex:page>

 

 

public class TestViewController {

    public String BegDate { get; set; }

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

//Variable of inner class to store array of incremented dates public DateBunches bDates {get; set;}

//Converts a string from mm/dd/yyyy 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]); Date retDate = date.newInstance(y,m,d);
bDates = new DateBunches(retDate);
return retDate; } }
public class DateBunches{
public Date dayDate1 {get; set;}
public Date dayDate2 {get; set;}
public Date dayDate3 {get; set;}
public Date dayDate4 {get; set;}
public Date dayDate5 {get; set;}
public Date dayDate6 {get; set;}

public DateBunches(Date startDate){
dayDate1 = startDate;
dayDate2 = startDate.addDays(1);
dayDate3 = startDate.addDays(2);
dayDate4 = startDate.addDays(3);
dayDate5 = startDate.addDays(4);
dayDate6 = startDate.addDays(5);
}
}
}

 

   The problem behind your question first posted is that, if you dont have a iterator vf tags, then you need to buid some inner classes like this for displaying array of values. You cannot refer to the list item to be displayed merely by referring to each item. (eg: <apex:outputText value="listDates[0]"/>)

   In case your requirement is more complex than simply showing increemented dates at 6 different places, then probably the approach has to be changed.