简体   繁体   中英

rich:calendar value does not change in bean

I have the following xhtml snippet where there are two rich:calendar (simply, date range for search):-

    <h:panelGroup>
            <h:outputText value="#{msg['lblstrtdteh']}" />
            <h:outputText value="   *" escape="false" styleClass="reqField" />
        </h:panelGroup>
        <rich:calendar id="startDateFldVhrs" datePattern="dd-MM-yyyy" locale="#{sessionBean.locale}"
            value="#{productsBean.startDate}" />

        <h:panelGroup>
            <h:outputText value="#{msg['lblenddteh']}" />
            <h:outputText value="   *" escape="false" styleClass="reqField" />
        </h:panelGroup>
        <rich:calendar id="endDateFldVhrs" datePattern="dd-MM-yyyy"
            value="#{productsBean.endDate}" />

Here's my bean's accessors:-

    /**
 * 
 * @return
 */
public Date getStartDate() {
    return startDate;
}

/**
 * 
 * @param startDate
 */
public void setStartDate(Date startDate) {
    this.startDate = startDate;
    System.out.println("setting startDate: " + startDate);
}

/**
 * 
 * @return
 */
public Date getEndDate() {
    return endDate;
}

/**
 * 
 * @param endDate
 */
public void setEndDate(Date endDate) {
    this.endDate = endDate;
    System.out.println("setting endDate: " + endDate);
}

When I select a different date than displayed, I don't see the print of setter methods, neither does it takes the displayed value when search button is fired (both dates are executed in the search commandButton). Something I am missing?

The fields are initialized with new Date() and it stays that way forever it seems.

In JSF your set methods is only called when you call an action, for example when you render or process a field, when you POST data to server, when some AJAX is called.

If you want your rich:calendar call your set method you show execute some AJAX and update your field.

Richfaces <= 3.X

 <a4j:form>
      <rich:calendar value="#{bean.date}" id="myCalendar">
          <a4j:support event="onchanged" reRender="myCalendar" ajaxSingle="true"/>
      </rich:calendar>
 </a4j:form>

Richfaces 4.X +

<rich:calendar id="myCalendar">
    <a4j:ajax event="change" execute="myCalendar" />
</rich:calendar>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM