// - remove any validators that don't have javascript functions defined.
for (final Iterator iterator = validatorTypes.iterator(); iterator.hasNext();)
{
final String type = (String)iterator.next();
final ValidatorAction action = JSFValidator.getValidatorAction(type);
final String functionName = this.getJavaScriptFunctionName(action);
if (StringUtils.isBlank(functionName))
{
iterator.remove();
}
}
for (final Iterator iterator = validatorTypes.iterator(); iterator.hasNext();)
{
final String type = (String)iterator.next();
final ValidatorAction action = JSFValidator.getValidatorAction(type);
if (!JAVASCRIPT_UTILITIES.equals(type))
{
writer.write("&& ");
writer.write(this.getJavaScriptFunctionName(action));
writer.write("(form)\n");
}
}
writer.write(";}\n");
// - for each validator type, write callback
for (final Iterator iterator = validatorTypes.iterator(); iterator.hasNext();)
{
final String type = (String)iterator.next();
final ValidatorAction action = JSFValidator.getValidatorAction(type);
String callback = action.getJsFunctionName();
if (StringUtils.isBlank(callback))
{
callback = type;
}
writer.write("function ");
writer.write(form.getId() + "_" + callback);
writer.write("() { \n");
// for each field validated by this type, add configuration object
final Map map = (Map)this.validators.get(type);
int ctr = 0;
for (final Iterator idIterator = map.keySet().iterator(); idIterator.hasNext(); ctr++)
{
final String id = (String)idIterator.next();
final JSFValidator validator = (JSFValidator)map.get(id);
writer.write("this[" + ctr + "] = ");
this.writeJavaScriptParams(
writer,
context,
id,
validator);
writer.write(";\n");
}
writer.write("}\n");
}
// - for each validator type, write code
for (final Iterator iterator = validatorTypes.iterator(); iterator.hasNext();)
{
final String type = (String)iterator.next();
final ValidatorAction action = JSFValidator.getValidatorAction(type);
writer.write(action.getJavascript());
writer.write("\n");
}
}