[izpack-devel] InstallationGroupPanel

Jeff Gordon jeff.not24 at gmail.com
Thu Jan 10 22:39:14 CET 2008


No problem,

I also have 2 other additions, but they are much more involved (I'm using
this in production by the way for a very well known company with global
reach).  They are multiple validator support and validators.

I added multiple validator support with parameters to the UserInputPanel
password field (it shouldn't break any existing validators).  I also took
the sample equality validator and made a PasswordEqualityValidator (which I
believe should be included as part of the primary distribution), and a
PasswordKeystoreValidator (which may be of some interest, but whether it
gets nominated for inclusion would be up to you and the group).

As an example, the PasswordEqualityValidator is below to show how the
parameters can be evaluated.  The PasswordKeystoreValidator is a bit longer,
but I can post that as well if anyone would like to see it.

- Jeff Gordon


----- PasswordEqualityValidator.java -----

package com.izforge.izpack.panels;

import java.util.Map;

public class PasswordEqualityValidator implements Validator {
  public boolean validate(ProcessingClient client) {
    boolean returnValue = false;
    Map params = getParams(client);
    try {
      returnValue = fieldsMatch(client);
      if (returnValue) {
        // Additional checking if params passed...
        if (params!=null) {
          System.out.println("Additional "+params.size()+" params not
evaluated");
        }
      }
    } catch (Exception e) {
      System.out.println("validate() Failed: "+e);
    }
    return (returnValue);
  }

  private Map getParams(ProcessingClient client) {
    PasswordGroup group = null;
    Map params = null;
    try {
      group = (PasswordGroup)client;
      if (group.hasParams()) {
        params = group.getValidatorParams();
      }
    } catch (Exception e) {
      System.out.println("getParams() Failed: "+e);
    }
    return (params);
  }

  private boolean fieldsMatch(ProcessingClient client) {
    boolean returnValue = true;
    int numFields = client.getNumFields();
    // ----------------------------------------------------
    // verify that there is more than one field. If there
    // is only one field we have to return true.
    // ----------------------------------------------------
    if (numFields < 2) {
      returnValue = true;
    } else {
      String content = client.getFieldContents(0);
      for (int i = 1; i < numFields; i++) {
        if (!content.equals(client.getFieldContents(i))) {
          returnValue = false;
        }
      }
    }
    return returnValue;
  }

}


On Jan 10, 2008 9:11 AM, Julien Ponge <julien.ponge at gmail.com> wrote:

> Hi Jeff, Sylvain,
>
> I will review your submissions shortly.
>
> Thanks a lot your feedback ;-)
> _______________________________________________
> izpack-devel mailing list
> izpack-devel at lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/izpack-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.berlios.de/pipermail/izpack-devel/attachments/20080110/3df7d1a7/attachment.html 


More information about the izpack-devel mailing list