You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by senore100 <se...@yahoo.com> on 2008/09/03 03:57:31 UTC

Validation error displayed by parent component?

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>




      

Re: Validation error displayed by parent component?

Posted by senore100 <se...@yahoo.com>.
Folks,
I've just figured out a solution. Just remove the <tr:panelLabelAndMessage> tags and it will do. But Trinidad is very new to me, and I still don't quite understand what is going on behind the scene here. So it would be great if anyone could kindly give me some explanation. Thanks...

--- On Tue, 9/2/08, senore100 <se...@yahoo.com> wrote:
From: senore100 <se...@yahoo.com>
Subject: Validation error displayed by parent component?
To: users@myfaces.apache.org
Cc: senore100@yahoo.com
Date: Tuesday, September 2, 2008, 8:57 PM

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>