NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
Luke Shannon Posted via mailing list.
|
Posted: Wed May 02, 2012 6:40 pm Post subject: [platform-dev] Validation Question |
|
|
I have added a Validation component to my TopComponent.
In the Post Creation Code I have this:
final ValidationGroup group = validationPanel1.getValidationGroup();
group.add(jTextField_baseOutputFileName, Validators.REQUIRE_NON_EMPTY_STRING);
jTextField_baseOutputFileName.getDocument().addDocumentListener(new
DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
checkValidation();
}
@Override
public void removeUpdate(DocumentEvent e) {
checkValidation();
}
@Override
public void changedUpdate(DocumentEvent e) {
checkValidation();
}
private void checkValidation() {
Problem validateAll = group.validateAll();
if (validateAll.isFatal()) {
jButton_Save_Details.setEnabled(false);
} else {
jButton_Save_Details.setEnabled(true);
}
}
});
The code that gets generated looks like this:
validationPanel1 = new org.netbeans.validation.api.ui.ValidationPanel();
final ValidationGroup group = validationPanel1.getValidationGroup();
group.add(jTextField_baseOutputFileName,
Validators.REQUIRE_NON_EMPTY_STRING);
jTextField_baseOutputFileName.getDocument().addDocumentListener(new
DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
checkValidation();
}
@Override
public void removeUpdate(DocumentEvent e) {
checkValidation();
}
@Override
public void changedUpdate(DocumentEvent e) {
checkValidation();
}
private void checkValidation() {
Problem validateAll = group.validateAll();
if (validateAll.isFatal()) {
jButton_Save_Details.setEnabled(false);
} else {
jButton_Save_Details.setEnabled(true);
}
}
});
All this seems OK, except I get a null pointer on this line when I try
and run the app. The offending line is:
group.add(jTextField_baseOutputFileName, Validators.REQUIRE_NON_EMPTY_STRING);
Why would the group be null? The only method it looked like I could set was:
validationPanel1.setInnerComponent(this) which didn't help.
Any tips?
Thanks,
Luke |
|
| Back to top |
|
 |
skyhook
Joined: 13 Apr 2012 Posts: 22
|
Posted: Mon Jul 09, 2012 11:52 am Post subject: Validation |
|
|
Hi Luke,
I am working with validation api...When i look to your code, i think i am missing...you have to set the "name" of item which you added to group. Something like:
JTextfield txtField = new JTextField();
txtField.setName("name'')
group.add(txtField, StringValidator).....
I can send you my example of class which is working.
Marek |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|