hi rudy,

thx for creating the add-on!
i'll have a look at it after the jsfdays.

@config parameter:
the add-on could also provide an optional web.xml context parameter for fine
grained deactivation.

regards,
gerhard

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces


2010/2/19 Rudy De Busscher <[email protected]>

> Gerhard,
>
> I created the addon and it is available at (1).  A demo app can be found
> here (2)
>
> The addon is based on a custom FacesMessageStorage as suggested by
> Gerhard.  The configurationParameter can be developed in cases where we
> don't want a global approach as with the addon.
>
> (1) =
> http://sandbox890.googlecode.com/svn/trunk/addons/uniqueValidationMessage
> (2) =
> http://sandbox890.googlecode.com/svn/trunk/examples/CrossValNoTargetMessage_extval
>
> Regards
> Rudy.
>
>
> On 18 February 2010 10:24, Gerhard Petracek <[email protected]>wrote:
>
>> hi rudy,
>>
>> you mentioned it correctly. it's a specific functionality
>> of AbstractCompareStrategy.
>>
>> as alternative it's possible to provide a custom FacesMessageStorage which
>> filters messages before they get added (directly
>> in FacesMessageStorage#addFacesMessage). that would allow a better
>> performance as well as an add-on instead of a configuration parameter.
>>
>> regards,
>> gerhard
>>
>> http://www.irian.at
>>
>> Your JSF powerhouse -
>> JSF Consulting, Development and
>> Courses in English and German
>>
>> Professional Support for Apache MyFaces
>>
>>
>> 2010/2/18 Rudy De Busscher <[email protected]>
>>
>> Hi all,
>>>
>>> There are cases that the validation message is shown twice for some Cross
>>> Validations.
>>>
>>> If we use for instance the Equals or NotEquals annotations where the
>>> target component is also shown on the same page, the message is shown twice.
>>> This is the example:
>>>
>>> *public class Person
>>> {
>>>     @NotEquals(value = "lastName", validationErrorMsgKey = "First name
>>> and last name can't have the same value")
>>>     private String firstName;
>>>
>>>     private String lastName;
>>> ...
>>> }
>>>
>>>
>>>     <h:messages />
>>>     <h:form>
>>>         <h:panelGrid columns="2">
>>>             <h:outputLabel value="First name" for="firstName" />
>>>             <h:inputText id="firstName"
>>> value="#{personBean.selectedPerson.firstName}" label="First Name" />
>>>             <h:outputLabel value="Last name" for="lastName" />
>>>             <h:inputText id="lastName"
>>> value="#{personBean.selectedPerson.lastName}" label="Last Name" />
>>>         ....
>>>         </h:panelGrid>
>>>     </h:form>*
>>>
>>> This is expected behaviour since the code wants to mark both fields as
>>> invalid and shows the message for each field.  But when the errors are
>>> displayed on the top of the page, the message seems to be duplicated. And in
>>> case of the above example with a custom validation message, it can be
>>> interpreted as a bug.
>>>
>>> The only way, I found, to avoid the 'duplicate' message (other then
>>> creating a custom strategy or annotation) was the creation of a
>>> ValidationExceptionInterceptor that filters out the duplicate message.
>>>
>>> *public class NoTargetMessageValidationExceptionInterceptor implements
>>>         ValidationExceptionInterceptor
>>> {
>>> public boolean afterThrowing(UIComponent uiComponent,
>>>             MetaDataEntry metaDataEntry, Object convertedObject,
>>>             ValidatorException validatorException,
>>>             ValidationStrategy validatorExceptionSource)
>>>     {
>>>         boolean result = true;
>>>
>>>         FacesMessageStorage storage =
>>> getStorage(FacesMessageStorage.class,
>>>                 FacesMessageStorage.class.getName());
>>>         for (FacesMessageHolder holder : storage.getFacesMessages())
>>>         {
>>>             if (holder.getFacesMessage().getDetail().equals(
>>>                     validatorException.getFacesMessage().getDetail()))
>>>             {
>>>                 result = false;
>>>             }
>>>         }
>>>         return result;
>>>     }
>>>     ...
>>> }*
>>>
>>> This code is not specific for Cross Validation messages, but is generic.
>>> But in most cases, a duplicate message comes from the usage of
>>> CrossValidation annotations.
>>>
>>> Should there be a configuration option (like a ValidationParameter)
>>> created in version x.x.4 so that the useTargetComponentToDisplayErrorMsg
>>> outcome is not only specified in the code but also by the annotation?
>>>
>>> regards
>>> Rudy
>>>
>>
>>
>

Reply via email to