Search code examples
install4j

Install4j Validation Script works incorrect


I have validation script on the my custom screen:

String host = (String)context.getVariable("httpHost");
String port = (String)context.getVariable("httpPort");
boolean isProxyNeed = context.getBooleanVariable("isProxyNeed");
if (isProxyNeed == true) {
    if (host.isEmpty()) {
        Util.showErrorMessage("Please enter a value for the 'host' field.");
        return false;
    } 
    if (port.isEmpty()) {
        Util.showErrorMessage("Please enter a value for the 'port' field.");
        return false;
    } 
}
return true;
  1. Host input validated correctly, but if fill it and press next button nothing happen.
  2. Port input doesn't validate at all.

P.S. In logs:

[ERROR] com.install4j.runtime.beans.screens.FormScreen [ID 221]: java.lang.NullPointerException
In screen "Proxy configuration [Form]" [ID 221], property "Validation expression":
java.lang.NullPointerException
    at com.install4j.script.I4jScript_Internal_149.eval(I4jScript_Internal_149.java:9)
    at com.install4j.script.I4jScript_Internal_149.evaluate(I4jScript_Internal_149.java:*37)
    at com.install4j.runtime.installer.helper.Script.evaluate(Script.java:33)

Solution

  • The reason for the exception is that httpHost and/or httpPort are null.