You need to sign in to do that
Don't have an account?
getting and setting and updating and getting!
Oh this seems so simple, yet I'm stuck!
Here's what I have now in my controller:
public date d { get{ d = date.today(); return d; } set; } public List<event> all { get { all = [select subject, activitydate, location from Event where activitydate = :d Order By location ASC]; return all; } set; }
All is peachy and the page loads up Today()'s info just fine.
Now, what I really want to do is load up the page initially with today's date and resulting info, but also have a button called "Next" that will add 1 day to the current date and update an outputPanel on my page with the new query results when clicked.
I know I need to add a function for the button action, but I'm not sure how to change the code above to manipulate the date variable accordingly.
Thanks in advance for any help you might provide!
You should be able to increment the date by calling d.addDays(1)
Not sure if this might help... But, here is an article which helps you understand getter and setter
http://www.forcetree.com/2009/07/getter-and-setter-methods-what-are-they.html
Ah yes, should have read that code more carefully. As it is written the getter is going to always return today's date, regardless of what you do in a setter.
You need d to be initialzed today's date in a constructor, then you can increment using d.addDays()
Hello, BryanTSC,
To clarify aballard's point, here's what your code may end up looking like:
P.S. What's interesting to me is that there is a significant difference between using the { get; set; } notation vs. defining actual get and set methods for a property. Thanks for bringing this to light, everyone!
Thanks, Marty.
I worked on this a bit this afternoon, though I admittedly don't fully understand what I have going on here. The page partially works, but it's not quite doing what I expect.
All joking aside - can anybody tell me what in my code is A) correct, B) wrong, and C) how to make this better/functional? I'm a motivated "learn by doing" kind of guy!
THANKS!
Hello, Bryan,
Would you give a few more details on what exactly is not working the way you want?
My initial feedback would be:
When I click the "prev" / "next" buttons I have set up, the schedule repeat div updates correctly, but the repeat for my "out" div disappears from the page.
If I click back to a date where data is available for "out", the "out" div reappears, but shows duplicate information, since the list is not getting cleared, but rather appended to.
I tried to add out = new list<event>(); in buildList() below the schedule=new list<event>(); line, but then my buttons don't appear to do anything when clicked.
Thanks for the other advice, commenting is definitely a practice I need to endorse!
The disappearing div is pretty interesting, and it has something to do with your partial page refresh (which isn't necessary for this page). I tested your code, and to fix the disappearing div issue all I did was remove the all-encompasing apex:outputPanel along with the reRender attributes from your apex:commandButton elements.
I'm also not seeing the "duplicate info" behavior you described. To me it appears that the rest of your code functions as you're expecting.
P.S. Your table header is missing a tr tag. th elements should always be nested within a tr element.
That definitely fixes the issue. I was attempting to use the partial page refresh as a way to make the data switch look more seamless than a full page refresh. Perhaps this isn't necessary or there is a better way to do it.