-
1. Re: Update Bean with selectedDate of Calendar
tomhain Oct 6, 2013 8:28 AM (in response to tomhain)Sorry, the source code disappeared. Here it is again:
<rich:calendar id="trainingCalendar2"
mode="ajax"
valueChangeListener="#{calendarModel.submit()}"
popup="false"
boundaryDatesMode="scroll"
locale="de/DE"
buttonLabel="Heute"
datePattern="dd.MM.yyyy"
dataModel="#{calendarModel}"
value="#{calendarModel.selectedDate}">
</rich:calendar><!-- The following date is always todays date, not the selected date of the calendar component -->
<h2>Training am #{calendarModel.selectedDate}:</h2> -
2. Re: Update Bean with selectedDate of Calendar
jhuska Oct 7, 2013 2:20 AM (in response to tomhain)Hello Tom,
You need to re-render the selected date information. You can do it with putting <a4j:ajax render event="change" render="selectedDateComponent id" /> into <rich:calendar>.
You will also need to add the id to the component like: <h2><h:outputText id="selectedDateComponent" value="#{calendar.selectedDAte}"/></h2>
You may find this post useful as well:
-
3. Re: Re: Update Bean with selectedDate of Calendar
tomhain Oct 7, 2013 5:26 AM (in response to jhuska)Hi Juraj,
thanks for your feedback. I tried the same, but it still does not work.
Here is my updated JSF:
<rich:calendar id="trainingCalendar2" mode="ajax" popup="false" boundaryDatesMode="scroll" locale="de/DE" buttonLabel="Heute" datePattern="dd.MM.yyyy" dataModel="#{calendarModel}" value="#{calendarModel.selectedDate}"> <a4j:ajax event="change" render="output" /> </rich:calendar> <h2><h:outputText id="output" value="#{calendarModel.selectedDate}" /> </h2>
The Bean itself is straight forward. However, to make it complete here are the relevant parts:
@ApplicationScoped @Named("calendarModel") public class CalendarModel implements CalendarDataModel { private Date selectedDate; // .... public void setSelectedDate(Date selectedDate) { this.selectedDate = selectedDate; } public Date getSelectedDate() { return selectedDate; } // ...
I even tried it with ValueChangeListener
valueChangeListener="#{calendarModel.onChangedDate}">
onChange="submit()"and the corresponding Java Code
public void onChangedDate(ValueChangeEvent e) { selectedDate = (Date)e.getNewValue(); log.info("onChangedDate, newValue " + e.getNewValue().toString()); }
But both variants do not work. Does somebody see the missing piece ? Thanks in advance!
-
4. Re: Update Bean with selectedDate of Calendar
tomhain Oct 7, 2013 6:54 AM (in response to tomhain)It works! I have forgotten to include the calendar in a form element. What a shame...
Thanks Juraj for your quick help!!