Reputation: 1895
I'm using RichFaces 3.3.3 and been trying to figure out how to set the Time portion of Rich:Cal
to be current System date instead of the Default 12:00
where the date pattern is dd/M/yyyy HH:mm
. I am also not interested using DefaultTime
attribute as its no use in my situation.
so Question is : Have i missed it or it is not possible to have current system time included when user selects a date cell?
2 - If the answer to above is not possible then what is the best way to implement such behaviour.
Would below be any good :
<rich:calendar id="richCal1"
value="#{cust.dateFrom1}"
datePattern="dd/M/yyyy HH:mm"
enableManualInput="true"
<f:convertDateTime pattern="dd/M/yyyy HH:mm" type="both"/>
<f:validator validatorId="#{cust.dateAppend}"/>
<f:attribute name="richCalendar" value="RichCalendar1" />
</rich:calendar>
So when user selects a date, in Backbean custom validator dateAppend
i will determine the element the trigger was fired from using the UIComponent.getAttributes() which for above code will be richCalendar
and hence know which backbean variable to update to overwrite default Time with System time. Sounds Hacky but i don't know any other way and should work.
I'm posting here so in case the above approach is totally wrong someone can let me know or offer advice on alternatives. Thanks
The above approach won't work since Setters are called at update model not at apply request phase and therefore i cannot change the value of backbean variable when the event is fired.
there must be a way. Any hints would be greatly appreciated.
Upvotes: 0
Views: 3144
Reputation: 4273
You need to implement a custom CalendarDataModel and assign it as dataModel for the calendar.
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.richfaces.model.CalendarDataModel;
import org.richfaces.model.CalendarDataModelItem;
@Name("richCalendarDataModel")
@BypassInterceptors
public class RichCalendarDataModel implements CalendarDataModel {
public CalendarDataModelItem[] getData(Date[] arg0) {
RichCalendarDataItem[] date = new RichCalendarDataItem[arg0.length];
int i = 0;
for (Date dd : arg0) {
Date myCustomDate = ...; //create your custom date here from original dd
RichCalendarDataItem tmp = new RichCalendarDataItem(myCustomDate, true);
date[i] = tmp;
i++;
}
return date;
}
public Object getToolTip(Date arg0) {
...
}
}
calendarDataModelItem:
import java.util.Date;
import org.richfaces.model.CalendarDataModelItem;
public class RichCalendarDataItem implements CalendarDataModelItem {
private Date data;
private boolean enabled;
public RichCalendarDataItem(Date dd, boolean en) {
data = dd;
enabled = en;
}
public int getDay() {
return 0;
}
public Object getData() {
return data;
}
public String getStyleClass() {
return null;
}
public Object getToolTip() {
return null;
}
public boolean hasToolTip() {
return false;
}
public boolean isEnabled() {
return enabled;
}
}
Upvotes: 1