NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

[platform-dev] Validation Question

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users
View previous topic :: View next topic  
Author Message
Luke Shannon
Posted via mailing list.





PostPosted: Wed May 02, 2012 6:40 pm    Post subject: [platform-dev] Validation Question Reply with quote

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

PostPosted: Mon Jul 09, 2012 11:52 am    Post subject: Validation Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo