I have a XHTML page in which there are four textboxes
<h:column >
<f:facet name="header">
<h:outputText value="Start Date" />
</f:facet>
<h:inputText id="startDate" value="#{sampleVO.startDate}" />
</h:column>
<h:column >
<f:facet name="header">
<h:outputText value="End Date" />
</f:facet>
<h:inputText id="endDate" value="#{sampleVO.endDate}" />
</h:column>
<h:column >
<f:facet name="header">
<h:outputText value="Start Date" />
</f:facet>
<h:inputText id="startDate1" value="#{sampleVO.startDate}" />
</h:column>
<h:column >
<f:facet name="header">
<h:outputText value="End Date" />
</f:facet>
<h:inputText id="endDate1" value="#{sampleVO.endDate}" />
</h:column>
I need to put a validation on Start Date and End Date. If user enters some Start and End date in id="startDate" & id="endDate" lets say Start Date: "01/01/2012" (1jan) and End Date: 01/31/2012 and if user enters some dates on id="startDate1" and id="endDate1" id="startDate1" should always be greater thn id="endDate" i.e date Ranges should not Overlap
public class SampleServiceimpl implements SampleService {
private List<SampleVO> listOfSample;
//this function gets called when clicked on Submit button on XHTML page
public Void submit() {
// how can i call datesOverLaps function to check entered
// start date and End date not overlapping, Also how to
// display the error message on XHTML page using FacingContext
}
public boolean datesOverlaps(List<SampleVO> sampleVO) {
final Date early = sampleVO.getStartDate();
final Date late = sampleVO.getEndDate();
for(SampleVO existing : sampleVO) {
if(!(early.isAfter(existing.getEnd())) ||
(late.isBefore(existing.getStart()))){
return true;
}
}
return false;
}
}
Not sure if the above boolean function is current and would work in the scenario. Any help would be appreciated.