I've written validation methods myself. The two dates are used to define a time
frame to generate a report. The 1st date cannot be a future date, and the 2nd
date cannot be earlier than the 1st date, nor can it be a future date.
Unfortunately, the error message in FacesMessage is always displayed twice.
I've googled about and explicitly set only "detail" but not "summary" (I've
tried the other way, and in that case, there will be no error message
displayed). From the expanded html, it looks like the repetition is either from
<tr:panelBox> or <tr:panelLabelAndMessage>, but I just don't know how to
disable displaying the message by a parent component. Can anyone shed any light
on this? Thanks a lot!
<!-- xhmtl snippet -->
<tr:panelBox text="Time Frame" styleClass="sub_panelbox">
<tr:panelFormLayout rows="1">
<tr:panelLabelAndMessage for="fromDate"
label="#{reportBean.descriptionFromDate}:">
<tr:inputDate id="fromDate" value="#{reportBean.fromDate}"
required="true" validator="#{reportAction.validateFromDate}">
<tr:convertDateTime pattern="MM/dd/yyyy"/>
</tr:inputDate>
</tr:panelLabelAndMessage>
<tr:panelLabelAndMessage for="toDate"
label="#{reportBean.descriptionToDate}:">
<tr:inputDate id="toDate" value="#{reportBean.toDate}" required="true"
validator="#{reportAction.validateToDate}">
<tr:convertDateTime pattern="MM/dd/yyyy"/>
</tr:inputDate>
</tr:panelLabelAndMessage>
</tr:panelFormLayout>
</tr:panelBox>
//Validation methods in ReportBean.java
public void validateFromDate(FacesContext context, UIComponent toValidate,
Object value)
{
if(value instanceof Date)
{
// validation for fromDate;
FacesMessage message = new FacesMessage();
message.setDetail("Report Start Date cannot be a future Date. Enter a
date before " + tomorrowDateString + ".");
message.setSummary(null);
throw new ValidatorException(message);
}
}
}
public void validateToDate(FacesContext context, UIComponent toValidate,
Object value)
{
if(value instanceof Date)
{
// Validation for toDate
FacesMessage message = new FacesMessage();
message.setDetail("Report End Date cannot be earlier than Start Date,
nor can it be a future date.");
message.setSummary(null);
throw new ValidatorException(message);
}
}
}
<!-- expanded html snippet -->
<td class="af_panelFormLayout_message-cell"><!--Start:
org.apache.myfaces.trinidad.SelectInput["fromDate"]--><span
id="caseInfoForm:fromDate::msg" class="OraInlineErrorText">Report Start Date
cannot be a future Date. Enter a date before 09/03/2008.</span></td>
</tr></table></td>
</tr></table><div class="af_panelFormLayout_message-cell"><!--Start:
org.apache.myfaces.trinidad.Panel["_id17"]--><span
id="caseInfoForm:fromDate::msg" class="OraInlineErrorText">Report Start Date
cannot be a future Date. Enter a date before 09/03/2008.</span></div></td>
</tr></tbody></table></td>