Keep last selected month on schedule after Ajax Update

UI Components for JSF
Post Reply
ufasoli
Posts: 42
Joined: 05 May 2010, 19:55

15 Jun 2010, 17:43

Hi,
I'm using a selectMany coupled with a

Code: Select all

p:ajax
in order to update a schedule.

here is my xhtml file :

Code: Select all

 <p:panel id="liste-employes" header="employés" rendered="#{sessionBean.isUserInRole('admin') || sessionBean.isUserInRole('dirigeant')}" toggleable="true">
                
               <h:form>

                    <h:selectManyCheckbox value="#{schedule.selectedItems}" id="selected-items" >
                        <f:selectItems value="#{schedule.selectItems}" />
                        <p:ajax update="liste-conges" event="change" actionListener="#{schedule.onSourcesChange}"/>
                        
                    </h:selectManyCheckbox>
                        
                </h:form>
           </p:panel>

            <div id="conges">

                <p:messages />


                <h:form prependId="false">
                    <p:schedule id="liste-conges" value="#{schedule.visualiseurConges}" editable="false" resizable="false" widgetVar="mesConges"  />
                </h:form>

on my backing bean method I simply add events using DefaultScheduleModel.addEvent()

The only problem is that each time the schedule is updated it goes back to the current date month , but what I need is for it to stay in the last selected month; is there any way to accomplish this?

thanks in advance

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

15 Jun 2010, 20:01

There is an initialDate attribute, if it is omitted, current date is displayed. Please see user's guide.

ufasoli
Posts: 42
Joined: 05 May 2010, 19:55

15 Jun 2010, 20:42

Hi, yes I saw the "initialDate" attribute, but how can I recover the last month displayed by the schedule if the user used the navigation buttons to change the month? should I bind the <p:schedule to an object on a backing bean?.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

16 Jun 2010, 20:26

I see, currently there is not a way to get notified when the user moves betweens months to keep the state, feel free to create an issue for that like viewChangeListener that will be invoked when user changes the view.

ufasoli
Posts: 42
Joined: 05 May 2010, 19:55

17 Jun 2010, 09:12

Will do, thank you !! :D


smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

09 Dec 2011, 00:07

Quote from http://code.google.com/p/primefaces/iss ... ail?id=930
Comment 2 by sigurd.s...@gmail.com, Aug 2, 2010
Just made a quick workaround to have this functionality for LazyScheduleModel.

In your implementation of LazyScheduleModel just create a date variable. Ie: private Date selectedDate;

In public void loadEvents(Date start, Date end) do the following:
GregorianCalendar g = new GregorianCalendar();
g.setTime(start);
g.add(Calendar.DAY_OF_MONTH, 12);
selectedDate = g.getTime();

This sets the date to somewhere in the middle of the month. Use this in the p:schedule component as initialDate
<p:schedule value="#{MyController.myModel}" initialDate="#{MyController.myModel.selectedDate}"

If your backing bean holding the controller is a session bean and you are using month view, the p:schedule will now remember which month was selected last if you navigate away from it.

This works, but I'm using Joda-Time (DateTime object/class) instead of GregorianCalendar. I almost had this implemented prior to researching this, but this puts the topping on the cake and works for me just great! Thank you!
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests