问题
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