You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Björn Voß <vo...@googlemail.com> on 2010/08/02 12:21:17 UTC

ExtVal cross field validation + Ajax

Hi,

I use the stack JSF 2 (RI 2.0.2) + ExtVal (2.0.4-SNAPSHOT) . With @Equals I
do a simple email check.

What I wanted to do is ajax validation and the equality is only checked if
the user leaves the secound input field?

Here are bean and facelet snipp:

################# bean snip
public class EmailBean {

    @Email //hibernate constrain
    @UniqueEmail //custom jr 303 annotation
    @NotEmpty //hibernate constrain
    private String email;

    @Equals
    private String emailRepeat;

################# facelet snipp

<h:panelGroup id="emailBlock" layout="block">
            <h:message id="emailInputMsg" for="emailInput"/>
            <h:outputLabel value="Email" />
            <h:inputText id="emailInput" value="#{emailBean.email}" >
                <f:ajax event="blur" execute="@this"
render="emailInputMsg"></f:ajax>
            </h:inputText>
        </h:panelGroup>
        <h:panelGroup id="emailRepeatBlock" layout="block">
            <h:message id="emailRepeatMsg" for="emailRepeatInput"/>
            <h:outputLabel value="Wiederholung-Email" />
            <h:inputText id="emailRepeatInput"
value="#{emailBean.emailRepeat}" >
                <f:ajax event="blur" execute="@this"
render="emailRepeatMsg"></f:ajax>
            </h:inputText>
        </h:panelGroup>

Now 2 things:
1. I want the equal validation only to happen on blur of the
emailRepeatInput
2. (nice to have) the equal error message only for repeat input

Is there a way to do this?
I have searched the ExtVal blog and the examples but I didn't find a
scenario like this.

regards
Björn

Re: ExtVal cross field validation + Ajax

Posted by Björn Voß <vo...@googlemail.com>.
hi gerhard,

thanks a lot, I'll try it later on and give you feedback tomorrow.

2010/8/3 Gerhard <ge...@gmail.com>

> hi björn,
>
> @#2:
> i've committed a first draft. you are welcome to use the current version -
> in your case [1].
>
> regards,
> gerhard
>
> [1]
>
> http://svn.apache.org/repos/asf/myfaces/extensions/validator/branches/branch_for_jsf_2_0/
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>
>
> 2010/8/2 Björn Voß <vo...@googlemail.com>
>
> > Hi,
> >
> > I use the stack JSF 2 (RI 2.0.2) + ExtVal (2.0.4-SNAPSHOT) . With @Equals
> I
> > do a simple email check.
> >
> > What I wanted to do is ajax validation and the equality is only checked
> if
> > the user leaves the secound input field?
> >
> > Here are bean and facelet snipp:
> >
> > ################# bean snip
> > public class EmailBean {
> >
> >    @Email //hibernate constrain
> >    @UniqueEmail //custom jr 303 annotation
> >    @NotEmpty //hibernate constrain
> >    private String email;
> >
> >    @Equals
> >    private String emailRepeat;
> >
> > ################# facelet snipp
> >
> > <h:panelGroup id="emailBlock" layout="block">
> >            <h:message id="emailInputMsg" for="emailInput"/>
> >            <h:outputLabel value="Email" />
> >            <h:inputText id="emailInput" value="#{emailBean.email}" >
> >                <f:ajax event="blur" execute="@this"
> > render="emailInputMsg"></f:ajax>
> >            </h:inputText>
> >        </h:panelGroup>
> >        <h:panelGroup id="emailRepeatBlock" layout="block">
> >            <h:message id="emailRepeatMsg" for="emailRepeatInput"/>
> >            <h:outputLabel value="Wiederholung-Email" />
> >            <h:inputText id="emailRepeatInput"
> > value="#{emailBean.emailRepeat}" >
> >                <f:ajax event="blur" execute="@this"
> > render="emailRepeatMsg"></f:ajax>
> >            </h:inputText>
> >        </h:panelGroup>
> >
> > Now 2 things:
> > 1. I want the equal validation only to happen on blur of the
> > emailRepeatInput
> > 2. (nice to have) the equal error message only for repeat input
> >
> > Is there a way to do this?
> > I have searched the ExtVal blog and the examples but I didn't find a
> > scenario like this.
> >
> > regards
> > Björn
> >
>

Re: ExtVal cross field validation + Ajax

Posted by Gerhard <ge...@gmail.com>.
hi björn,

@#2:
i've committed a first draft. you are welcome to use the current version -
in your case [1].

regards,
gerhard

[1]
http://svn.apache.org/repos/asf/myfaces/extensions/validator/branches/branch_for_jsf_2_0/

http://www.irian.at

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

Professional Support for Apache MyFaces



2010/8/2 Björn Voß <vo...@googlemail.com>

> Hi,
>
> I use the stack JSF 2 (RI 2.0.2) + ExtVal (2.0.4-SNAPSHOT) . With @Equals I
> do a simple email check.
>
> What I wanted to do is ajax validation and the equality is only checked if
> the user leaves the secound input field?
>
> Here are bean and facelet snipp:
>
> ################# bean snip
> public class EmailBean {
>
>    @Email //hibernate constrain
>    @UniqueEmail //custom jr 303 annotation
>    @NotEmpty //hibernate constrain
>    private String email;
>
>    @Equals
>    private String emailRepeat;
>
> ################# facelet snipp
>
> <h:panelGroup id="emailBlock" layout="block">
>            <h:message id="emailInputMsg" for="emailInput"/>
>            <h:outputLabel value="Email" />
>            <h:inputText id="emailInput" value="#{emailBean.email}" >
>                <f:ajax event="blur" execute="@this"
> render="emailInputMsg"></f:ajax>
>            </h:inputText>
>        </h:panelGroup>
>        <h:panelGroup id="emailRepeatBlock" layout="block">
>            <h:message id="emailRepeatMsg" for="emailRepeatInput"/>
>            <h:outputLabel value="Wiederholung-Email" />
>            <h:inputText id="emailRepeatInput"
> value="#{emailBean.emailRepeat}" >
>                <f:ajax event="blur" execute="@this"
> render="emailRepeatMsg"></f:ajax>
>            </h:inputText>
>        </h:panelGroup>
>
> Now 2 things:
> 1. I want the equal validation only to happen on blur of the
> emailRepeatInput
> 2. (nice to have) the equal error message only for repeat input
>
> Is there a way to do this?
> I have searched the ExtVal blog and the examples but I didn't find a
> scenario like this.
>
> regards
> Björn
>

Re: ExtVal cross field validation + Ajax

Posted by Gerhard <ge...@gmail.com>.
hi björn,

are you sure that there is no other issue?
i've tried to reproduce #1 and it looks like everything is working
correctly.
please put a breakpoint at the beginning of
AbstractValidationInterceptor#beforeGetConvertedValue and post the value(s)
returned by
FacesContext.getCurrentInstance().getPartialViewContext().getExecuteIds();
furthermore, you should see just one invocation
of CrossValidationUserInputRecorder#recordUserInput in the described
constellation.

regards,
gerhard

http://www.irian.at

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

Professional Support for Apache MyFaces


2010/8/2 Gerhard <ge...@gmail.com>

> short addition:
>
> @#1:
>
> for sure you can provide a custom implementation.
> you can impl. a custom storage for processed information >or< cross
> validation entries.
> that's possible via a custom storage manager. if you are using the default
> storage manager, you can also use a custom name-mapper (with a higher
> priority).
> your custom name-mapper has to point to your custom storage.
>
> e.g. via:
> StorageManager storageManager =
> ExtValContext.getContext().getFactoryFinder()
>     .getFactory(FactoryNames.STORAGE_MANAGER_FACTORY,
> StorageManagerHolder.class)
>     .getStorageManager(ProcessedInformationStorage.class);
>
> if(storageManager instanceof AbstractNameMapperAwareFactory)
> {
>     ((AbstractNameMapperAwareFactory<String>)storageManager)
>         .register(new CustomProcessedInformationStorageNameMapper());
> }
>
> the CustomProcessedInformationStorageNameMapper has to be annotated
> with @InvocationOrder //+ a value < 200
> now your custom storage implementation can use
> PartialViewContext#getExecuteIds to filter the components which get added to
> the storage.
>
> regards,
> gerhard
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>
> 2010/8/2 Gerhard <ge...@gmail.com>
>
> hi björn,
>>
>> #1: it isn't supported right now.
>> #2 you could override EqualsStrategy#useTargetComponentToDisplayErrorMsg
>> and return false -> register your custom validation strategy
>> anyway, we can enhance the annotation.
>>
>> please file two jira tickets for these improvements.
>>
>> regards,
>> gerhard
>>
>> http://www.irian.at
>>
>> Your JSF powerhouse -
>> JSF Consulting, Development and
>> Courses in English and German
>>
>> Professional Support for Apache MyFaces
>>
>>
>> 2010/8/2 Björn Voß <vo...@googlemail.com>
>>
>> Hi,
>>>
>>> I use the stack JSF 2 (RI 2.0.2) + ExtVal (2.0.4-SNAPSHOT) . With @Equals
>>> I
>>> do a simple email check.
>>>
>>> What I wanted to do is ajax validation and the equality is only checked
>>> if
>>> the user leaves the secound input field?
>>>
>>> Here are bean and facelet snipp:
>>>
>>> ################# bean snip
>>> public class EmailBean {
>>>
>>>    @Email //hibernate constrain
>>>    @UniqueEmail //custom jr 303 annotation
>>>    @NotEmpty //hibernate constrain
>>>    private String email;
>>>
>>>    @Equals
>>>    private String emailRepeat;
>>>
>>> ################# facelet snipp
>>>
>>> <h:panelGroup id="emailBlock" layout="block">
>>>            <h:message id="emailInputMsg" for="emailInput"/>
>>>            <h:outputLabel value="Email" />
>>>            <h:inputText id="emailInput" value="#{emailBean.email}" >
>>>                <f:ajax event="blur" execute="@this"
>>> render="emailInputMsg"></f:ajax>
>>>            </h:inputText>
>>>        </h:panelGroup>
>>>        <h:panelGroup id="emailRepeatBlock" layout="block">
>>>            <h:message id="emailRepeatMsg" for="emailRepeatInput"/>
>>>            <h:outputLabel value="Wiederholung-Email" />
>>>            <h:inputText id="emailRepeatInput"
>>> value="#{emailBean.emailRepeat}" >
>>>                <f:ajax event="blur" execute="@this"
>>> render="emailRepeatMsg"></f:ajax>
>>>            </h:inputText>
>>>        </h:panelGroup>
>>>
>>> Now 2 things:
>>> 1. I want the equal validation only to happen on blur of the
>>> emailRepeatInput
>>> 2. (nice to have) the equal error message only for repeat input
>>>
>>> Is there a way to do this?
>>> I have searched the ExtVal blog and the examples but I didn't find a
>>> scenario like this.
>>>
>>> regards
>>> Björn
>>>
>>
>>
>

Re: ExtVal cross field validation + Ajax

Posted by Gerhard <ge...@gmail.com>.
short addition:

@#1:

for sure you can provide a custom implementation.
you can impl. a custom storage for processed information >or< cross
validation entries.
that's possible via a custom storage manager. if you are using the default
storage manager, you can also use a custom name-mapper (with a higher
priority).
your custom name-mapper has to point to your custom storage.

e.g. via:
StorageManager storageManager =
ExtValContext.getContext().getFactoryFinder()
    .getFactory(FactoryNames.STORAGE_MANAGER_FACTORY,
StorageManagerHolder.class)
    .getStorageManager(ProcessedInformationStorage.class);

if(storageManager instanceof AbstractNameMapperAwareFactory)
{
    ((AbstractNameMapperAwareFactory<String>)storageManager)
        .register(new CustomProcessedInformationStorageNameMapper());
}

the CustomProcessedInformationStorageNameMapper has to be annotated
with @InvocationOrder //+ a value < 200
now your custom storage implementation can use
PartialViewContext#getExecuteIds to filter the components which get added to
the storage.

regards,
gerhard

http://www.irian.at

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

Professional Support for Apache MyFaces


2010/8/2 Gerhard <ge...@gmail.com>

> hi björn,
>
> #1: it isn't supported right now.
> #2 you could override EqualsStrategy#useTargetComponentToDisplayErrorMsg
> and return false -> register your custom validation strategy
> anyway, we can enhance the annotation.
>
> please file two jira tickets for these improvements.
>
> regards,
> gerhard
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>
> 2010/8/2 Björn Voß <vo...@googlemail.com>
>
> Hi,
>>
>> I use the stack JSF 2 (RI 2.0.2) + ExtVal (2.0.4-SNAPSHOT) . With @Equals
>> I
>> do a simple email check.
>>
>> What I wanted to do is ajax validation and the equality is only checked if
>> the user leaves the secound input field?
>>
>> Here are bean and facelet snipp:
>>
>> ################# bean snip
>> public class EmailBean {
>>
>>    @Email //hibernate constrain
>>    @UniqueEmail //custom jr 303 annotation
>>    @NotEmpty //hibernate constrain
>>    private String email;
>>
>>    @Equals
>>    private String emailRepeat;
>>
>> ################# facelet snipp
>>
>> <h:panelGroup id="emailBlock" layout="block">
>>            <h:message id="emailInputMsg" for="emailInput"/>
>>            <h:outputLabel value="Email" />
>>            <h:inputText id="emailInput" value="#{emailBean.email}" >
>>                <f:ajax event="blur" execute="@this"
>> render="emailInputMsg"></f:ajax>
>>            </h:inputText>
>>        </h:panelGroup>
>>        <h:panelGroup id="emailRepeatBlock" layout="block">
>>            <h:message id="emailRepeatMsg" for="emailRepeatInput"/>
>>            <h:outputLabel value="Wiederholung-Email" />
>>            <h:inputText id="emailRepeatInput"
>> value="#{emailBean.emailRepeat}" >
>>                <f:ajax event="blur" execute="@this"
>> render="emailRepeatMsg"></f:ajax>
>>            </h:inputText>
>>        </h:panelGroup>
>>
>> Now 2 things:
>> 1. I want the equal validation only to happen on blur of the
>> emailRepeatInput
>> 2. (nice to have) the equal error message only for repeat input
>>
>> Is there a way to do this?
>> I have searched the ExtVal blog and the examples but I didn't find a
>> scenario like this.
>>
>> regards
>> Björn
>>
>
>

Re: ExtVal cross field validation + Ajax

Posted by Gerhard <ge...@gmail.com>.
hi björn,

#1: it isn't supported right now.
#2 you could override EqualsStrategy#useTargetComponentToDisplayErrorMsg and
return false -> register your custom validation strategy
anyway, we can enhance the annotation.

please file two jira tickets for these improvements.

regards,
gerhard

http://www.irian.at

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

Professional Support for Apache MyFaces


2010/8/2 Björn Voß <vo...@googlemail.com>

> Hi,
>
> I use the stack JSF 2 (RI 2.0.2) + ExtVal (2.0.4-SNAPSHOT) . With @Equals I
> do a simple email check.
>
> What I wanted to do is ajax validation and the equality is only checked if
> the user leaves the secound input field?
>
> Here are bean and facelet snipp:
>
> ################# bean snip
> public class EmailBean {
>
>    @Email //hibernate constrain
>    @UniqueEmail //custom jr 303 annotation
>    @NotEmpty //hibernate constrain
>    private String email;
>
>    @Equals
>    private String emailRepeat;
>
> ################# facelet snipp
>
> <h:panelGroup id="emailBlock" layout="block">
>            <h:message id="emailInputMsg" for="emailInput"/>
>            <h:outputLabel value="Email" />
>            <h:inputText id="emailInput" value="#{emailBean.email}" >
>                <f:ajax event="blur" execute="@this"
> render="emailInputMsg"></f:ajax>
>            </h:inputText>
>        </h:panelGroup>
>        <h:panelGroup id="emailRepeatBlock" layout="block">
>            <h:message id="emailRepeatMsg" for="emailRepeatInput"/>
>            <h:outputLabel value="Wiederholung-Email" />
>            <h:inputText id="emailRepeatInput"
> value="#{emailBean.emailRepeat}" >
>                <f:ajax event="blur" execute="@this"
> render="emailRepeatMsg"></f:ajax>
>            </h:inputText>
>        </h:panelGroup>
>
> Now 2 things:
> 1. I want the equal validation only to happen on blur of the
> emailRepeatInput
> 2. (nice to have) the equal error message only for repeat input
>
> Is there a way to do this?
> I have searched the ExtVal blog and the examples but I didn't find a
> scenario like this.
>
> regards
> Björn
>