Hello All,
I have Custom Validator problem.
I have two input calenders and I want to make some validation on their values
any validation.
so this the UI
code:
<h:outputText value="From Date:" style="font-weight:bold"/>
<t:inputCalendar id="FromDate" monthYearRowClass="yearMonthHeader" weekRowClass="weekHeader"
currentDayCellClass="currentDayCell" value="#{positionPopup.fromDate}" renderAsPopup="true"
popupTodayString="#{example_messages['popup_today_string']}" popupWeekString="#{example_messages['popup_week_string']}"
renderPopupButtonAsImage="true" required="true" styleClass="required">
<f:validator validatorId="
validators.datesOverlapValidator"/>
</t:inputCalendar>
<h:outputText value="Thru Date:" style="font-weight:bold" />
<t:inputCalendar id="ThruDate" monthYearRowClass="yearMonthHeader" weekRowClass="weekHeader"
currentDayCellClass="currentDayCell" value="#{positionPopup.thruDate}" renderAsPopup="true"
popupTodayString="#{example_messages['popup_today_string']}" popupWeekString="#{example_messages['popup_week_string']}"
renderPopupButtonAsImage="true" required="false">
</t:inputCalendar>
and this is the validator
code:
public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) throws ValidatorException
{
if (facesContext == null) throw new NullPointerException("facesContext");
if (uiComponent == null) throw new NullPointerException("uiComponent");
if (value == null)
{
return;
}
UIComponent foreignComp = uiComponent.getParent().findComponent(_for); // _for = "ThruDate" // equall to the second inputCalender ID
if(foreignComp==null)
throw new FacesException("Unable to find component '" + _for + "' (calling findComponent on component '" +
uiComponent.getId() + "')");
if(false == foreignComp instanceof EditableValueHolder)
throw new FacesException("Component '" + foreignComp.getId() + "' does not implement EditableValueHolder");
EditableValueHolder foreignEditableValueHolder = (EditableValueHolder) foreignComp;
if (foreignEditableValueHolder.isRequired() && foreignEditableValueHolder.getValue()== null )
{
return;
}
Object[] args = {value.toString(),(foreignEditableValueHolder.getValue()==null) ? foreignComp.getId():foreignEditableValueHolder.getValue().toString()};
_logger.info(" From Date = "+ args[0].toString() +" Thrue Date = "+foreignEditableValueHolder.getValue());
boolean overlap = this.overlap
( new Range(new Date(1), new Date(2)), new Range(new Date(1), new Date(2)));
if(!overlap)
{
//if(foreignEditableValueHolder.getValue()==null || !foreignEditableValueHolder.getValue().toString().equals(
value.toString()) )
FacesMessage message = new FacesMessage();
message.setDetail(Messages.getMessageString("RangeOverlapValidator")+" "+ args[0].toString() +" "+args[1].toString() + ".");
message.setSummary(Messages.getMessageString("RangeOverlapValidator")+" "+ args[0].toString() +" "+args[1].toString() + ".");
message.setSeverity
(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(message);
}
}
but it always return the ThruDate = null however it can feel with it's properties like isRequired or not.
Can Any buddy help?
--
Ali Abdel-Aziz
http://www.aliabdelaziz.com
http://aabdelaziz.blogspot.com
- Custom Validator problem. Ali Abdel-Aziz Ali
- Re: Custom Validator problem. Gilles DEMARTY
- Re: Custom Validator problem. Ali Abdel-Aziz Ali
- RE: Custom Validator problem. Julian Ray

