简体   繁体   中英

How to send selected date of rich:calendar to my bean?

I am using richfaces calendar in my JSF 1.1 project. If I select a date, I want to send the selected date to my bean. How can I do it? I write simple code for this but it comes always null.

Here is my JSF page:

<rich:panel style="width: 15%;">
    <rich:calendar cellWidth="24px" cellHeight="22px" value="#{functions.selectedDate}"
        datePattern="yyyy-MM-dd" style="width:200px;">
    </rich:calendar>
</rich:panel>

Here is my bean:

import java.util.Date;

public class functions {

    private Date selectedDate;

    public Date getSelectedDate() {
        return selectedDate;
    }

    public void setSelectedDate(Date selectedDate) {
        this.selectedDate = selectedDate;
    }

}

Put it in a <h:form> and submit it by a command button/link inside the same form.

Eg

<rich:panel style="width: 15%;">
    <h:form>
        <rich:calendar cellWidth="24px" cellHeight="22px" value="#{functions.selectedDate}"
            datePattern="yyyy-MM-dd" style="width:200px;">
        </rich:calendar>
        <h:commandButton value="submit" action="#{functions.submit}" />
    </h:form>
</rich:panel>

with

public void submit() {
    System.out.println("Selected date is: " + selectedDate);
}

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