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

↘锁芯ラ 提交于 2019-12-13 00:37:28

问题


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;
    }

}

回答1:


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

E.g.

<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);
}


来源:https://stackoverflow.com/questions/7502280/how-to-send-selected-date-of-richcalendar-to-my-bean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!