如何将 Rich:calendar 的选定日期发送到我的 bean? [英] How to send selected date of rich:calendar to my bean?

查看:61
本文介绍了如何将 Rich:calendar 的选定日期发送到我的 bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JSF 1.1 项目中使用 Richfaces 日历.如果我选择一个日期,我想将所选日期发送到我的 bean.我该怎么做?我为此编写了简单的代码,但它始终为空.

这是我的 JSF 页面:

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

这是我的豆子:

import java.util.Date;公共类函数{私人日期选择日期;公共日期 getSelectedDate() {返回选定日期;}public void setSelectedDate(Date selectedDate) {this.selectedDate = selectedDate;}}

解决方案

将其放入 并通过同一表单内的命令按钮/链接提交.>

例如

<h:形式><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>

public void submit() {System.out.println("选择日期为:" + selectedDate);}

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.

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

这篇关于如何将 Rich:calendar 的选定日期发送到我的 bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆