There is regular requirement is, the from date and To date should accept same day(Same date).
And also From date should accept less than the to date and equal like to date also should accept greater than or equal of the from date.
This kind of reqirement we can achieve by UI level.
There is a component is VALIDATE DATE TIME RANGE, but wont work in the case of from date and to date is in same date.
For this kind of requirement we can handle at Entity level is easiest way.
For this I have created validation methods at Entity attribute level from date and to date.
Those methods are pointed to your entity impl classess.
The logic inside methods :
/**
* Validation method for Todate.
*/
public boolean validateTodate(Date todate) {
if(null != toDateLocal && null != fromDateLocal){
int compareValue = toDateLocal.compareTo(fromDateLocal);
if(compareValue == -1 ){
return false;
}
}
return true;
}
/**
* Validation method for Fromdate.
*/
public boolean validateFromdate(Date fromdate) {
if(null != toDateLocal && null != fromDateLocal){
int compareValue = fromDateLocal.compareTo(toDateLocal);
if(compareValue == 1 ){
return false;
}
}
return true;
}
Here fromDateLocal and toDateLocal are the class level varibales, should get values from setter and getter.
/**
* Gets the attribute value for Fromdate, using the alias name Fromdate.
* @return the Fromdate
*/
public Date getFromdate() {
fromDateLocal = (Date)getAttributeInternal(FROMDATE);
return (Date)getAttributeInternal(FROMDATE);
}
/**
* Sets <code>value</code> as the attribute value for Fromdate.
* @param value value to set the Fromdate
*/
public void setFromdate(Date value) {
fromDateLocal = value;
setAttributeInternal(FROMDATE, value);
}
/**
* Gets the attribute value for Todate, using the alias name Todate.
* @return the Todate
*/
public Date getTodate() {
toDateLocal = (Date)getAttributeInternal(TODATE);
return (Date)getAttributeInternal(TODATE);
}
/**
* Sets <code>value</code> as the attribute value for Todate.
* @param value value to set the Todate
*/
public void setTodate(Date value) {
toDateLocal = value;
setAttributeInternal(TODATE, value);
}
In UI you just set auto submit true for from and to date components.
Happy Coding.. :)
And also From date should accept less than the to date and equal like to date also should accept greater than or equal of the from date.
This kind of reqirement we can achieve by UI level.
There is a component is VALIDATE DATE TIME RANGE, but wont work in the case of from date and to date is in same date.
For this kind of requirement we can handle at Entity level is easiest way.
For this I have created validation methods at Entity attribute level from date and to date.
Those methods are pointed to your entity impl classess.
The logic inside methods :
/**
* Validation method for Todate.
*/
public boolean validateTodate(Date todate) {
if(null != toDateLocal && null != fromDateLocal){
int compareValue = toDateLocal.compareTo(fromDateLocal);
if(compareValue == -1 ){
return false;
}
}
return true;
}
/**
* Validation method for Fromdate.
*/
public boolean validateFromdate(Date fromdate) {
if(null != toDateLocal && null != fromDateLocal){
int compareValue = fromDateLocal.compareTo(toDateLocal);
if(compareValue == 1 ){
return false;
}
}
return true;
}
Here fromDateLocal and toDateLocal are the class level varibales, should get values from setter and getter.
/**
* Gets the attribute value for Fromdate, using the alias name Fromdate.
* @return the Fromdate
*/
public Date getFromdate() {
fromDateLocal = (Date)getAttributeInternal(FROMDATE);
return (Date)getAttributeInternal(FROMDATE);
}
/**
* Sets <code>value</code> as the attribute value for Fromdate.
* @param value value to set the Fromdate
*/
public void setFromdate(Date value) {
fromDateLocal = value;
setAttributeInternal(FROMDATE, value);
}
/**
* Gets the attribute value for Todate, using the alias name Todate.
* @return the Todate
*/
public Date getTodate() {
toDateLocal = (Date)getAttributeInternal(TODATE);
return (Date)getAttributeInternal(TODATE);
}
/**
* Sets <code>value</code> as the attribute value for Todate.
* @param value value to set the Todate
*/
public void setTodate(Date value) {
toDateLocal = value;
setAttributeInternal(TODATE, value);
}
In UI you just set auto submit true for from and to date components.
Happy Coding.. :)