Two Calendars trying to restrict maxDate and minDate problem

UI Components for JSF
Post Reply
nikola.fi.82
Posts: 1
Joined: 10 Jan 2011, 10:46

10 Jan 2011, 11:12

Hi, i'm using JSF2.0 on GlassfishV3 and I have two p:calendar components, and i want a behavior that goes like this:
-when i select a date on first it restricts maxDate on second
-when i select a date on second it restricts minDate on first

My problem is that when i select a value and rerender components it writes values which were upon initialization (when i first came to the page, it reverts them) :(

on boxView.xthml:

Code: Select all

<ui:repeat value="#{updateBoxController.currentBoxRegisterList}" var="register" varStatus="status">
	<h:panelGroup id="boxRegisters" styleClass="boxRegisters" layout="block" >
		<h:panelGroup id="boxRegistersValuePanel" >
			<p:calendar id="fromDateCalendarSelector" styleClass="registerCalendar" value="#{register.fromDate}" mode="popup" 
					  selectListener="#{updateBoxController.handleFromDateSelect}" effect="fadeIn" navigator="true" showWeek="true" 
                  			  maxdate="#{updateBoxController.getFormattedDate(register.toDate)}" onSelectUpdate="fromDateCalendarSelector toDateCalendarSelector">
     				<f:attribute name="index" value="#{status.index}"/>
			</p:calendar>
				
			<p:calendar id="toDateCalendarSelector" styleClass="registerCalendar" value="#{register.toDate}" mode="popup" 
                 				selectListener="#{updateBoxController.handleToDateSelect}" effect="fadeIn" navigator="true" showWeek="true" 
                 				mindate="#{updateBoxController.getFormattedDate(register.fromDate)}" onSelectUpdate="fromDateCalendarSelector toDateCalendarSelector" >
    			 	<f:attribute name="index" value="#{status.index}"/>
			</p:calendar>
		</h:panelGroup>
	</h:panelGroup>
</ui:repeat>
Session scoped bean:

Code: Select all

public class UpdateBoxController implements Serializable {
     private List<RegisterModel> currentBoxRegisterList;

     //method which is called on h:commandButton Action in another page which leads to boxView.xthml
     public String selectBox() {
          ...
          currentBoxRegisterList = boxModel.getRegisterModelList();
          ...

          return "toBoxViewPage";
     }

    //===   p:Calendar events   ===//
    public void handleFromDateSelect(DateSelectEvent event) {
        Calendar calendar = (Calendar) event.getSource();
        currentBoxRegisterList.get((Integer) calendar.getAttributes().get("index")).setFromDate(event.getDate());
    }

    public void handleToDateSelect(DateSelectEvent event) {
        Calendar calendar = (Calendar) event.getSource();
        currentBoxRegisterList.get((Integer) calendar.getAttributes().get("index")).setToDate(event.getDate());
    }
}
Class which holds data from database:

Code: Select all

public class RegisterModel implements Comparable<RegisterModel> {
     ...
     private Date fromDate;
     private Date toDate;

     public RegisterModel() {
         fromDate = new Date();
         toDate = new Date();
     }

     public Date getFromDate() {
        return fromDate;
    }

    public void setFromDate(Date fromDate) {
        this.fromDate = fromDate;
    }

    public Date getToDate() {
        return toDate;
    }

    public void setToDate(Date toDate) {
        this.toDate = toDate;
    }
     ...
}

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 52 guests