On Jan 27, 2012, at 3:23 PM, Christophe Laprun wrote:
On Jan 27, 2012, at 2:04 PM, Julien Viet wrote:
> looking in webui there is already a configuration for validation in the package
org.exoplatform.webui.config.
>
> The class org.exoplatform.webui.config.Component class has a list of validators
associated with it, each validator has an InitParams objects.
>
> This can be loaded from XML, a sample is visible there
http://anonsvn.jboss.org/repos/gatein/portal/trunk/webui/core/src/test/re...
it contains among other:
>
> <validators>
> <validator>
> <type>class.name</type>
> <init-params>
>
<param><name>name</name><value>value</value></param>
> </init-params>
> </validator>
> </validators>
Good to know, I will look into it.
> The class we want to make configured externally is the class UIGroupMembershipForm.
I actually don't think that's the only place. See for example UIAccountInputSet,
UIAccountProfiles, UIRegisterInputSet, UIAccountEditInputSet and possibly others. There
are way too many spots where usernames are dealt with and they are not dealt with in a
consistent way.
https://issues.jboss.org/browse/GTNPORTAL-2186 changed some of the validation process in
some spots but didn't in other for unknown reasons. Regardless of what is being done
with the configuration aspects of the validation, a rational validation process for
usernames (and other important data) needs to be put in place.
> I foresee two steps to investigate
>
> 1/ we should try to see if we can first remove the validation hardcoded in
UIGroupMembershipForm and instead use XML.
> 2/ we should find a way to make this configuration overridden externally with
additional configuration in conf directory.
I will investigate these issues but we need to think about cleaning up the validation of
data more deeply.
First results of the investigation:
The information that might come from the XML configuration is converted into a
org.exoplatform.webui.config.Component object that is used by UIComponent. However, the
Component.getValidators method doesn't seem to be called from anywhere in the code.
Moreover, based upon further investigation, while it may be possible to leverage WebUI
configuration files for the purpose of injecting user-defined validation patterns, it
would require way too much work for users to do so as they would:
1. need to edit the exoadmin.war portlet.xml file for each portlet they want to customize
validation. That requires unzipping the war file.
2. copy whatever is in the file pointed at by the webui.configuration init param for that
portlet into a new file and make that parameter point to that new file
3. edit that file to include the original content and add a validator section with the
appropriate information
4. rezip the exoadmin.war file with potential implications on jar signing
In theory, this would work but this is really complicated for something that many users
want to do. In practice, I am not even sure that such mechanism would work.
Alternatively, we could support the defaulting mechanism that's available at the
kernel level where values can be dynamically replaced at runtime with support for default
values.
For example: ${gatein.conf.dir:classpath:/conf}/wsrp-producer-config.xml would result in
the kernel first looking for a file in the gatein.conf.dir with the name
wsrp-producer-config.xml. If that file is not found, then it will look for the same file
under classpath:/conf. A similar mechanism could be introduced for resource resolvers at
the portlet level meaning that we could change the exoadmin portlet.xml to contain such
defaults so that the users could place an appropriately named file in gatein.conf.dir that
would be used in priority over the default one found in exoadmin.war.
This solution would, however, be only marginally easier for users since they would still
need to copy the content of the original file before adding the appropriate validators
section, which is not only far from intuitive but also error prone as they would have to
repeat the process for each portlet they want to customize. This would also require a new
resource resolving mechanism. If configuration could be additive instead of erasing, that
would be a step in the right direction but that comes with its own set of (potentially
worse) issues…
All of this also relies on the fact that validators can actually be injected which I
haven't been able to verify so far (a search for usage of the Component.getValidators
method returns no match, though it might be called in .gtmpl which break traditional usage
search of IDEs).
So I'd recommend developing a custom solution better targeted at our users' need.
I will write a specification for it but I also expect a specification document for the
username accepted format so that I can properly define what the constraints need to be.
Cordialement / Best,
Chris
==
Principal Software Engineer / JBoss Enterprise Middleware Red Hat, Inc.
Follow GateIn:
http://blog.gatein.org /
http://twitter.com/gatein
Follow me:
http://metacosm.info/metacosm /
http://twitter.com/metacosm