When I enter 00/00/0000 into the date range filter (before and from the date) on the web page, it is saved as 11/30/0002.
I try to use setLenient(false)but no luck. Here is the piece of code. Hope it helps. I am including a webpage code that takes values and code from bean support.
XHTML Page Code:
<h:panelGroup layout="block" styleClass="myWorkDate">
<h:commandLink action="#{myFollowupBean.startRangeFilter}" id="lnkDateRange" value="#{myFollowupBean.rangeFilter.display}" />
</h:panelGroup>
MyFollowUpBean.java: Bean file
The code in the backup bean. A dialog box appears for the date range filter. When I enter zero, it saves as 11/30/0002 and processes the request instead of giving an error RangeFilterVO - model class for dates
public void startRangeFilter() {
Command saveCommand = new Command() {
@Override
public String execute(Object returnObject) {
RangeFilterVO vo = (RangeFilterVO)returnObject;
rangeFilter.setFromDate(vo.getFromDate());
rangeFilter.setToDate(vo.getToDate());
searchAll();
fetch();
return null;
}
};
CalendarRangeFilterDialog dialog = new CalendarRangeFilterDialog();
dialog.setWidth(300);
try {
RangeFilterVO param = (RangeFilterVO) BeanUtils
.cloneBean(rangeFilter);
dialog.setVo(param);
} catch (IllegalAccessException | InstantiationException
| InvocationTargetException | NoSuchMethodException e) {
}
DialogFrame.displayDialog(dialog, saveCommand);
}
DateTimeConverter.java:
public static String getDatePattern(){
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, FacesUtils.getLocale());
String datePattern = ((SimpleDateFormat) dateFormat).toPattern();
Date myDate;
try {
if(myDate == dateFormat.parse(datePattern)){
if (datePattern.indexOf("MM") == -1){
datePattern = StringUtils.replace(datePattern, "M", "MM");
}
if (datePattern.indexOf("dd") == -1){
datePattern = StringUtils.replace(datePattern, "d", "dd");
}
if (datePattern.indexOf("yyyy") == -1){
datePattern = StringUtils.replace(datePattern, "yy", "yyyy");
}
}
} catch (ParseException e) {
e.printStackTrace();
}
return datePattern;
}
Can someone explain me more about this?
source
share