Okay, I'm implementing this, but I need some help..

My idea was to add a locale parameter to struts.validator containing a standard java.util.Locale string and then use that to figure out which validators goes into which <formset>, but I've run into a couple of issues. See example below:

The following code:

   /**
    * @struts.validator
    *      type="required"
    *
    * @struts.validator
    *      type="date"
    *
      * @struts.validator-var
    *      name="datePatternStrict"
    *      value="dd-MM-yyyy"
    *
    * @struts.validator
   *      type="date"
   *         locale="en"
    *
    * @struts.validator-var
    *      name="datePatternStrict"
     *      value="MM-dd-yyyy"
    */
   public void setFrom(String pFrom) {
       mFrom = pFrom;
   }

should result into the following validation.xml:

<formset>
   ...
         <form name="Step1Form">
                 <field property="from"
                        depends="required,date">

                     <arg0 key="Step1Form.from"/>
                     <var>
                       <var-name>datePatternStrict</var-name>
                       <var-value>dd-MM-yyyy</var-value>
                     </var>
                 </field>
            </form>
</formset>
<formset language="en">
   ...
         <form name="Step1Form">
                 <field property="from"
                        depends="required,date">

<arg0 key="Step1Form.from"/>
<var>
<var-name>datePatternStrict</var-name>
<var-value>MM-dd-yyyy</var-value>
</var>
</field>
</form>
</formset>
But that raises the following problems with my current code:


- I first find all the validator's without locale including required and the default date validator, OK. Next I find the validator with locale="en" which isn't including required, which is then missing from <formset language="en">. I have now way to now which validators is international and which should be localized..

- When parsing the Form class I have no garantie that the struts.validator's and struts.validator-var's is in the above order. Some might place all the struts.validator's first and then struts.validator-var's. This leaves me with no clue which struts.validator-var's belong to which struts.validator's (without great knowledge of commons-validator internals)...

My new idea is to place the locale parameter on all validator tags; struts.validator, struts.validator-args and struts.validator-var and expand the locale parameter with the non-standard values null/"all" and "default". With the meaning that the particula struts.validator, struts.validator-args or struts.validator-var should be in all <formset>'s or in the default <formset> only.

The above code would now configured like:

   /**
    * @struts.validator
    *      type="required"
    *      locale="all"
    *
    * @struts.validator
    *      type="date"
    *                                    <= No locale = locale="all"
    *
      * @struts.validator-var
    *      name="datePatternStrict"
    *      value="dd-MM-yyyy"
    *      locale="default"
    *
    * @struts.validator-var
    *      name="datePatternStrict"
     *      value="MM-dd-yyyy"
   *         locale="en"
    */
   public void setFrom(String pFrom) {
       mFrom = pFrom;
   }

Is this usable and in true XDoclet spirit or complete insane??

Thanks,

Christian Bjørnbak

Christian Bjørnbak wrote:

Hi

Struts supports localized validation by having multiple <formset>'s in validation.xml - one for each "known" locale and one fallback/default for "unknown" locales.

E.g.

validation.xml:
...
<formset>
...
</formset>
<formset language="en" country="GB">
...
</formset>
<formset language="da">
...
</formset>
...

In the default <formset> you insert the default validation rules and then only overrides the changed rules in the various localized <formset>'s. In the above example that could be override the postalcode format in the british locale and the postal code and date formats in the danish locale.

This is great for validation of localized input like dates and floats, but isn't supported by XDoclet that will only create the default <formset>...

I'm considering improving XDoclet/validation_xml.xdt with ability to handle locales.

I was thinking of the following design:

Adding three parameters to @struts.validator; language, country and variant.

Then I'll extend validation_xml.xdt to do the following:
1. Find all the fields without language, country or variant and create the default <formset>. (Almost the current behaviour).
2. Find all the combinations of language, country and variant used in all classes.
3. Foreach combination create a <formset> containing only the field's different from the default.


As I'm a xdt/XDoclet programming newbie I would like to here somebody's opinion about:
- Can this be done with xdt?
- Is this too difficult for a starters project?


/Christian Bjørnbak


------------------------------------------------------- This SF.Net email is sponsored by: InterSystems CACHE FREE OODBMS DOWNLOAD - A multidimensional database that combines robust object and relational technologies, making it a perfect match for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8 _______________________________________________ xdoclet-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-devel




-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to