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
reshmareshma 

How to get selectlist and date values from visualforce page to controller

<apex:inputField name='journeydate' value="{!task.activityDate}"/> 
 
How to write getters and setters for this date field to get the value in the controller
I wrote

public void setJourneydate(Date d){

     System.debug(' journeydate : '+d );

    }

          public Date getJourneydate()

    {

     Date dd;

    return dd;

    }

<apex:selectList size='1' name='reserveclass' multiselect="true"> <apex:selectOptions value="{!options}"/> </apex:selectList>

How to write getters and setters for this date field to get the value in the controller
I wrote

public List<SelectOption> getOptions()

    {

    return options;

    }

    public List<SelectOption> getStateoptions()

    {

    return stateoptions;

    }

which is not working.

 

 

reshmareshma
Can anyone suggest a solution for the above problem.
TehNrdTehNrd
For the first part:

Code:
In controller:
Task mytask = new Task();

public Task getmytask(){
    return mytask;
}
//I believe the data binding is automatic and you do not need setter methods.
//to reference the date, getMyTask().activityDate;

In the page: <apex:inputField name='journeydate' value="{!mytask.activityDate}"/>

 Second part:

Code:
String[] reservedClasses = new String[]{};

public String[] getreservedClasses () {
return reservedClasses ;
}

public void setreservedClasses (String[] reservedClasses ) {
this.reservedClasses = reservedClasses ;
}


Page:
<apex:selectList size='1' name='reserveclass' multiselect="true" value="{!reservedClasses}"> <apex:selectOptions value="{!options}"/> </apex:selectList>

 

reshmareshma
Hi TehNrd
Thanks for the response
I  have to get the date selected in the page to controller.
If Iam using this the output is default system date.
But when Iam trying to change the date iam not able to see it in the controller.
 
reshmareshma
Thanks for the second one it worked fine
TehNrdTehNrd
Post your code if you can, be sure to use the <apex:inputField> tag and not <apex:inputText>
reshmareshma
In controller i have written this to display a calendar in page
Task t = new Task();
public Task getTask()    
 {        
  return t;    
 }    
 
 
Iam able to get a calendar here.But after selection i want to gat the selected date in controller
<apex:inputField name='journeydate' value="{!task.activityDate}"/>
 
for that in controller
Date t;
public void setJourneydate(Date t)    
 {        
  t=this.t;   
 } 
public Date getJourneydate()    
 {        
  return t;    
 } 
jwetzlerjwetzler
You don't need your getters and setters for journeyDate.  You were headed down the right path -- normally with a field that is not actually going to be saved on an SObject, like yours, you want your getters and setters so that you can use them in your controller.  However inputField gives you a lot of cool stuff for Dates like the date picker/calendar, and inputFields have to be bound to an sobject field, so that's  why TehNrd has you using a task that is acting as a sort of proxy to get you the date picker functionality.

The point of that long explanation: To useit in your controller now, you just have to reference t.activityDate.


Message Edited by jwetzler on 06-06-2008 06:45 AM

Message Edited by jwetzler on 06-06-2008 06:45 AM