You need to sign in to do that
Don't have an account?
SFmaverick
getList based on user input
Currently my controller looks like this:
public class ScheduleViewController { public List<Shift__c> getTheList() { List<Shift__c> TheList = [SELECT Shift_Summary__c, Shift_Summary_2__c, Shift_Summary_3__c, Day_of_week__c FROM Shift__c WHERE Date__c = TODAY]; System.Debug('MY LIST:' + TheList); return TheList; } }
The list is filtered by the date, where the Date is equal to today. Instead, I'd like the user to be able to specify a date and have the list pulled from that date. I'm not sure how I can pass the date as a parameter to the controller method.\
My current call to the list is simply:
<apex:dataList value="{!TheList}" var="item">
How would I go about querying that list based on a user specified date?
I'd suggest the following, though there are no doubt other ways to implement this:
(1) Create an input element on your VF page that captures the date - which one of these you choose depends on how you are storing the date - e.g. an sobject field, a text field that is converted to a date etc.
(2) Set the value of the input element to a property from your controller.
(3) Create an apex:actionfunction that invokes a method on your controller to rebuild "thelist" based on the property value.
(4) Add a rerender attribute to your actionfunction so that it just redraws the datalist
(5) Add an onchange event to your input element that calls the actionfunction
You can use <apex:param> component along with <apex:datalist> to pass date as a parameter.
I'm unfamiliar with how to use <apex:param>, maybe you can help me out? Here's the current code from my page / controller. I'm currently getting this error:
My Page code is:
and my controller code is (with the lines giving the error highlighted in red:
Appreciate all the help!
I'm sure this got resolved, but for anyone coming to this thread, the stringtodate error was caused by the following lines:
as BegDate is not initialized, only declared, it will have a value of null. In the stringToDate function, this value is assumed not to be null:
the solution is either to null protect the stringToDate function, or move the initialisation of DayDate to the constructor, and ensuring that BegDate has a value.