You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Frost, Gary [IT]" <Ga...@ssmb.com.au> on 2002/12/12 00:04:48 UTC

Validator Formsets search by Locale

Hi,

Seem to have run into another issue with the validator.  I have a
validator.xml 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons
Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
<!-- Define the Validations for the Logon related forms -->
<form-validation>
	<global />
	<formset >
		<form name="logonForm">
			<field property="username" depends="required">
			    <arg0 key="text.general.username" />
			</field>
		    <field property="password" depends="required">
				<arg0 key="text.general.password" />
			</field>
		</form>
	</formset>
</form-validation>

I.e. its in the default/non specified locale.  (BTW The globals are defined
elsewhere and load properly)

So, I use validator successfully on a logon page.  If a user comes to the
page and their locale is not set (i.e. no entry under Globals.LOCALE_KEY at
Session scope) that the default locale of en (no country) is set. 

Then I find that in the ValidatorResources.java    :
public Form get(String language, String country, String variant, Object
formKey) 

method, that the call 
Vector v = (Vector) hFormSets.get(key);    (where key = "en") 

that the formset is successfully returned, and then the validator form
(logonForm) is successfully found.

However if there is an entry in Globals.LOCALE_KEY, Session scope, and their
locale is set to en_AU, that the call to 
Vector v = (Vector) hFormSets.get(key);    (where key = "en_AU")    returns
null, 
And hence no validator form can be found (of course, cos there's no formset
to find it in).

So, while its easy for me to fix this in the logon area, simply by removing
the session scope LOCALE_KEY, it does present a problem in other parts of
the application where a value is set.

My understanding that the formsets should be searched for the given form in
order of 
    *    <li>language + country + variant</li>
    *    <li>language + country</li>
    *    <li>language</li>
    *    <li>default locale</li>

Where as (from what I see in that method), the formset for the
language,country,variant passed in is found, then it is search for the given
formKey name.... The more I look at this method the more it looks like a
bug, 

Given 

<!ELEMENT formset (constant*, form+)>
<!ATTLIST formset language     CDATA #IMPLIED
                  country      CDATA #IMPLIED >
<!ELEMENT form    (field+ )>
<!ATTLIST form    name         CDATA #REQUIRED>

I.e. formsets have language and country, forms do not.

And that the code

	key = /// KEYS ARRANGE IN ORDER SPECIFIED ABOVE         
	formsets = v.elements();
	while (formsets.hasMoreElements()) {
	    o = formsets.nextElement();
	    if (o != null) {
		fs = (FormSet)o;
		if ((fs != null) && (fs.getForm(formKey) != null)) {
		    return fs.getForm(formKey);
		}
	    }
	}

keeps getting repeated (with the key changing, but the code does not...)

I'm pretty new to the validator stuff so I could definitely be barking up
the wrong tree, please advise if I am, and if so would appreciate input on
how I should set up my formsets (and even my LOCAL keys) to make the search
correctly

Should the code be more like the code in the attached file (again probably
got stuff all messed up in my head) 

Thanks

Gary


 <<validatorResource-get-method.java>>