You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Bruno Dumon <br...@outerthought.org> on 2004/04/27 12:58:42 UTC

WidgetValidators: do they need FormContext?

I was just looking at adding widget validators on widget instances and
found it's already there. Cool :-)

Still a question about the WidgetValidator interface:

public interface WidgetValidator {
    boolean validate(Widget widget, FormContext context);
}

will a validator ever need the FormContext object?

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: WidgetValidators: do they need FormContext?

Posted by Bruno Dumon <br...@outerthought.org>.
On Wed, 2004-04-28 at 15:28, Sylvain Wallez wrote:
> Bruno Dumon wrote:
> 
> >On Tue, 2004-04-27 at 23:35, Sylvain Wallez wrote:
> ><snip/> 
> >  
> >
> >>I was about to propose to not only remove FormContext from validate 
> >>(it's useless), but also to remove FormContext completely.
> >>    
> >>
> >
> >ok, one step at a time: so it's ok to remove FormContext from
> >WidgetValidator right now?
> >  
> >
> 
> +1.
> 
> >>Don't yell at me right now. Read on ;-)
> >>
> >>Remember those discussions we had last august about request adapters [1] 
> >>which turned out to be actually environment adapters [2]? Using a 
> >>LocaleAdapter would allow us to finally use *the* location where we 
> >>naturally can get it: request.getLocale().
> >>
> >>It's just a matter of writing a RequestWrapper that returns the locale 
> >>accordingly to the browser/cookie/session-attr scheme we have today, and 
> >>we can stop worrying about these locale that have to be passed around in 
> >>the code and these {lang} everywhere in the sitemap.
> >>
> >>WDYT?
> >>    
> >>
> >
> >In general, I think it would be a good thing to have one place to get
> >the locale from. I'm not sure yet how these request adapaters would
> >work, eg would it be needed to do instanceof checks on the Request
> >object to see if it is a "LocalizedRequest" or something?
> >  
> >
> 
> Nonono!! The purpose of request adapters is to provide the application 
> with the correct data transparently. Think of it as ServletFilters 
> inside Cocoon.

ok. I was confused by the request.getLocale() method, but now I see this
method actually exists on the Request object already.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: WidgetValidators: do they need FormContext?

Posted by Sylvain Wallez <sy...@apache.org>.
Bruno Dumon wrote:

>On Tue, 2004-04-27 at 23:35, Sylvain Wallez wrote:
><snip/> 
>  
>
>>I was about to propose to not only remove FormContext from validate 
>>(it's useless), but also to remove FormContext completely.
>>    
>>
>
>ok, one step at a time: so it's ok to remove FormContext from
>WidgetValidator right now?
>  
>

+1.

>>Don't yell at me right now. Read on ;-)
>>
>>Remember those discussions we had last august about request adapters [1] 
>>which turned out to be actually environment adapters [2]? Using a 
>>LocaleAdapter would allow us to finally use *the* location where we 
>>naturally can get it: request.getLocale().
>>
>>It's just a matter of writing a RequestWrapper that returns the locale 
>>accordingly to the browser/cookie/session-attr scheme we have today, and 
>>we can stop worrying about these locale that have to be passed around in 
>>the code and these {lang} everywhere in the sitemap.
>>
>>WDYT?
>>    
>>
>
>In general, I think it would be a good thing to have one place to get
>the locale from. I'm not sure yet how these request adapaters would
>work, eg would it be needed to do instanceof checks on the Request
>object to see if it is a "LocalizedRequest" or something?
>  
>

Nonono!! The purpose of request adapters is to provide the application 
with the correct data transparently. Think of it as ServletFilters 
inside Cocoon.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: WidgetValidators: do they need FormContext?

Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2004-04-27 at 23:35, Sylvain Wallez wrote:
<snip/> 
> I was about to propose to not only remove FormContext from validate 
> (it's useless), but also to remove FormContext completely.

ok, one step at a time: so it's ok to remove FormContext from
WidgetValidator right now?

> Don't yell at me right now. Read on ;-)
> 
> Remember those discussions we had last august about request adapters [1] 
> which turned out to be actually environment adapters [2]? Using a 
> LocaleAdapter would allow us to finally use *the* location where we 
> naturally can get it: request.getLocale().
> 
> It's just a matter of writing a RequestWrapper that returns the locale 
> accordingly to the browser/cookie/session-attr scheme we have today, and 
> we can stop worrying about these locale that have to be passed around in 
> the code and these {lang} everywhere in the sitemap.
> 
> WDYT?

In general, I think it would be a good thing to have one place to get
the locale from. I'm not sure yet how these request adapaters would
work, eg would it be needed to do instanceof checks on the Request
object to see if it is a "LocalizedRequest" or something?

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: WidgetValidators: do they need FormContext?

Posted by Sylvain Wallez <sy...@apache.org>.
Bruno Dumon wrote:

>On Tue, 2004-04-27 at 13:21, Marc Portier wrote:
>  
>
>>Bruno Dumon wrote:
>>
>>    
>>
>>>I was just looking at adding widget validators on widget instances and
>>>found it's already there. Cool :-)
>>>
>>>Still a question about the WidgetValidator interface:
>>>
>>>public interface WidgetValidator {
>>>    boolean validate(Widget widget, FormContext context);
>>>}
>>>
>>>will a validator ever need the FormContext object?
>>>
>>>      
>>>
>>I had the same question popin' up when looking at validate(FormContext) 
>>on widget.. only thing I could imagine was that it might be useful to 
>>have access to the Locale?
>>    
>>
>
>the Locale shouldn't even be needed.
>
>Just found a possible reason: until recently the flowcontext, which is
>passed on to the javascript validator snippets, was passed on via the
>request object. Now that's done via the objectModel so at least for that
>purpose it's not needed anymore. (and I've made the listenerbuilders
>into 'real' avalon components so they could get it via contextualize as
>well).
>  
>

Cool job! We can get rid of these ugly CocoonComponentManager hacks.

>>And I would need to take a deeper look but probably one could (today) 
>>obtain the same through widget.getFormDefinition().getLocale()
>>    
>>
>
>typo: getForm() instead of getFormDefinition()
>
>I think we should keep that method for internal purposes only (I would
>make that method protected). Normally the locale is only needed during
>the readFromRequest/conversion cycle, but because that conversion is now
>sometimes delayed till the getValue, the locale needs to be stored as
>well. (I know you know that, just mentioning it for the audience)
>  
>

I was about to propose to not only remove FormContext from validate 
(it's useless), but also to remove FormContext completely.

Don't yell at me right now. Read on ;-)

Remember those discussions we had last august about request adapters [1] 
which turned out to be actually environment adapters [2]? Using a 
LocaleAdapter would allow us to finally use *the* location where we 
naturally can get it: request.getLocale().

It's just a matter of writing a RequestWrapper that returns the locale 
accordingly to the browser/cookie/session-attr scheme we have today, and 
we can stop worrying about these locale that have to be passed around in 
the code and these {lang} everywhere in the sitemap.

WDYT?

>>this assumes that validation is called after readFromRequest() (no pro) 
>>but would also assume that if validation needs to happen after binding 
>>(doesn't ATM) this locale on form should be set
>>    
>>

You shouldn't need the locale to validate after a setValue, since the 
value is locale-independent (it's the convetor's job).

Sylvain

[1] http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=106131747919501&w=2
[2] http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=106164807007073&w=2

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: WidgetValidators: do they need FormContext?

Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2004-04-27 at 13:21, Marc Portier wrote:
> Bruno Dumon wrote:
> 
> > I was just looking at adding widget validators on widget instances and
> > found it's already there. Cool :-)
> > 
> > Still a question about the WidgetValidator interface:
> > 
> > public interface WidgetValidator {
> >     boolean validate(Widget widget, FormContext context);
> > }
> > 
> > will a validator ever need the FormContext object?
> > 
> 
> I had the same question popin' up when looking at validate(FormContext) 
> on widget.. only thing I could imagine was that it might be useful to 
> have access to the Locale?

the Locale shouldn't even be needed.

Just found a possible reason: until recently the flowcontext, which is
passed on to the javascript validator snippets, was passed on via the
request object. Now that's done via the objectModel so at least for that
purpose it's not needed anymore. (and I've made the listenerbuilders
into 'real' avalon components so they could get it via contextualize as
well).

> 
> And I would need to take a deeper look but probably one could (today) 
> obtain the same through widget.getFormDefinition().getLocale()

typo: getForm() instead of getFormDefinition()

I think we should keep that method for internal purposes only (I would
make that method protected). Normally the locale is only needed during
the readFromRequest/conversion cycle, but because that conversion is now
sometimes delayed till the getValue, the locale needs to be stored as
well. (I know you know that, just mentioning it for the audience)

> 
> this assumes that validation is called after readFromRequest() (no pro) 
> but would also assume that if validation needs to happen after binding 
> (doesn't ATM) this locale on form should be set
> 
> regards,
> -marc=
-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: WidgetValidators: do they need FormContext?

Posted by Marc Portier <mp...@outerthought.org>.

Bruno Dumon wrote:

> I was just looking at adding widget validators on widget instances and
> found it's already there. Cool :-)
> 
> Still a question about the WidgetValidator interface:
> 
> public interface WidgetValidator {
>     boolean validate(Widget widget, FormContext context);
> }
> 
> will a validator ever need the FormContext object?
> 

I had the same question popin' up when looking at validate(FormContext) 
on widget.. only thing I could imagine was that it might be useful to 
have access to the Locale?

And I would need to take a deeper look but probably one could (today) 
obtain the same through widget.getFormDefinition().getLocale()

this assumes that validation is called after readFromRequest() (no pro) 
but would also assume that if validation needs to happen after binding 
(doesn't ATM) this locale on form should be set

regards,
-marc=
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at                http://blogs.cocoondev.org/mpo/
mpo@outerthought.org                              mpo@apache.org