Skip to content

Commit

Permalink
Fix nullpointer
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed May 25, 2016
1 parent 638d1ab commit 88951b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract class BankForm extends PaymentMethodForm {
private InputTextField bankNameInputTextField, bankIdInputTextField, branchIdInputTextField, accountNrInputTextField, holderIdInputTextField;
private TextField currencyTextField;
private Label holderIdLabel;
private InputTextField holderNameInputTextField;
protected InputTextField holderNameInputTextField;
private Label bankIdLabel;
private Label branchIdLabel;
private Label accountNrLabel;
Expand All @@ -63,6 +63,7 @@ abstract class BankForm extends PaymentMethodForm {
private Label accountTypeLabel;
private ComboBox<String> accountTypeComboBox;
private boolean validatorsApplied;
private boolean useHolderID;

static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountContractData paymentAccountContractData) {
BankAccountContractData data = (BankAccountContractData) paymentAccountContractData;
Expand Down Expand Up @@ -274,7 +275,6 @@ public Country fromString(String s) {
branchIdLabel.setText(BankUtil.getBranchIdLabel(countryCode));
accountNrLabel.setText(BankUtil.getAccountNrLabel(countryCode));
accountTypeLabel.setText(BankUtil.getAccountTypeLabel(countryCode));
holderIdLabel.setText(BankUtil.getHolderIdLabel(countryCode));

bankNameInputTextField.setText("");
bankIdInputTextField.setText("");
Expand All @@ -285,39 +285,48 @@ public Country fromString(String s) {

if (BankUtil.useValidation(countryCode) && !validatorsApplied) {
validatorsApplied = true;
holderIdInputTextField.setValidator(inputValidator);
if (useHolderID)
holderIdInputTextField.setValidator(inputValidator);
bankNameInputTextField.setValidator(inputValidator);
bankIdInputTextField.setValidator(new BankIdValidator(countryCode));
branchIdInputTextField.setValidator(new BranchIdValidator(countryCode));
accountNrInputTextField.setValidator(new AccountNrValidator(countryCode));
} else {
validatorsApplied = false;
holderIdInputTextField.setValidator(null);
if (useHolderID)
holderIdInputTextField.setValidator(null);
bankNameInputTextField.setValidator(null);
bankIdInputTextField.setValidator(null);
branchIdInputTextField.setValidator(null);
accountNrInputTextField.setValidator(null);
}
holderNameInputTextField.resetValidation();
holderIdInputTextField.resetValidation();
bankNameInputTextField.resetValidation();
bankIdInputTextField.resetValidation();
branchIdInputTextField.resetValidation();
accountNrInputTextField.resetValidation();


boolean requiresHolderId = BankUtil.isHolderIdRequired(countryCode);
if (requiresHolderId) {
holderNameInputTextField.minWidthProperty().unbind();
holderNameInputTextField.setMinWidth(300);
} else {
holderNameInputTextField.minWidthProperty().bind(currencyTextField.widthProperty());
holderIdInputTextField.setText("");
}
holderIdLabel.setVisible(requiresHolderId);
holderIdLabel.setManaged(requiresHolderId);
holderIdInputTextField.setVisible(requiresHolderId);
holderIdInputTextField.setManaged(requiresHolderId);

if (useHolderID) {
if (!requiresHolderId)
holderIdInputTextField.setText("");

holderIdInputTextField.resetValidation();
holderIdInputTextField.setVisible(requiresHolderId);
holderIdInputTextField.setManaged(requiresHolderId);

holderIdLabel.setText(BankUtil.getHolderIdLabel(countryCode));
holderIdLabel.setVisible(requiresHolderId);
holderIdLabel.setManaged(requiresHolderId);
}


boolean bankNameRequired = BankUtil.isBankNameRequired(countryCode);
bankNameTuple.first.setVisible(bankNameRequired);
Expand Down Expand Up @@ -438,6 +447,7 @@ protected void addHolderNameAndId() {
holderNameInputTextField.minWidthProperty().bind(currencyTextField.widthProperty());
holderNameInputTextField.setValidator(inputValidator);

useHolderID = true;
holderIdLabel = tuple.third;
holderIdLabel.setVisible(false);
holderIdLabel.setManaged(false);
Expand Down Expand Up @@ -508,7 +518,7 @@ && getCountryBasedPaymentAccount().getCountry() != null
if (BankUtil.isAccountTypeRequired(countryCode))
result &= bankAccountContractData.getAccountType() != null;

if (BankUtil.isHolderIdRequired(countryCode))
if (useHolderID && BankUtil.isHolderIdRequired(countryCode))
result &= holderIdInputTextField.getValidator().validate(bankAccountContractData.getHolderTaxId()).isValid;
}
allInputsValid.set(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SameBankForm(PaymentAccount paymentAccount, InputValidator inputValidator
@Override
protected void addHolderNameAndId() {
Tuple2<Label, InputTextField> tuple = addLabelInputTextField(gridPane, ++gridRow, "Account holder name:");
InputTextField holderNameInputTextField = tuple.second;
holderNameInputTextField = tuple.second;
holderNameInputTextField.setValidator(inputValidator);
holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
bankAccountContractData.setHolderName(newValue);
Expand Down

0 comments on commit 88951b5

Please sign in to comment.