mgarcia
|
Posted: May 26, 2009 21:35 by mgarcia
|
|
The project wiki depicts some screenshots of forms showing warning messages. I would like to be able to generate that kind of warnings myself. I am using a code pattern very similar to the sample in the wiki. Is there any similar way to make the validators generate a warning and not an error (use case: I would like users not entering "Name" to have an error reported, but not entering the optional field "Description" just trigger a warning. Thanks. |
Create/show warning messages
26 topics, 113 posts
» Share this
Replies: 8 - Last Post: February 09, 2010 00:02
by: hugoheden
by: hugoheden
showing 1 - 9 of 9
Tim Boudreau
|
Posted: November 26, 2009 18:26 by Tim Boudreau
|
|
FYI, I've just added the ability to do this - see Validators.limitSeverity(Severity, Validator)
|
cnish_09
|
Posted: December 28, 2009 20:40 by cnish_09
|
|
Hi Tim, I am planning to use this framework for validating my swing components. I have one constraint using this... i.e.. If i have three text fields say Name1 and Name2 and Name3in my Panel and i am making both as mandatory one by giving Validators.REQUIRE_NON_EMPTY_STRING. both the text fields are added to the same validation group of a validation panel. Now when i run the application the user tries to enter a valid text say 'abc' in Name1, Immediately the error message is shown saying "Name2 cannot be empty", which he never entered at all. This is one problem for me, since the error message is shown even when the user has not entered it.. ![]() Below is the code snippet sample....
package validationsample;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.netbeans.validation.api.builtin.Validators;
import org.netbeans.validation.api.ui.ValidationPanel;
public class NBValidator extends JFrame{
/**
* @param args the command line arguments
*/
public NBValidator(){
ValidationPanel validationPanel=new ValidationPanel();
this.setContentPane(validationPanel);
JPanel panel=new JPanel();
JLabel nameLab1=new JLabel("Name1: ");
JTextField nameTxt1=new JTextField("",10);
JLabel nameLab2=new JLabel("Name2: ");
JTextField nameTxt2=new JTextField(10);
JLabel nameLab3=new JLabel("Name3: ");
JTextField nameTxt3=new JTextField(10);
panel.add(nameLab1, rootPane);
panel.add(nameTxt1, rootPane);
panel.add(nameLab2, rootPane);
panel.add(nameTxt2, rootPane);
panel.add(nameLab3, rootPane);
panel.add(nameTxt3, rootPane);
validationPanel.getValidationGroup().add(nameTxt1,Validators.MAY_NOT_START_WITH_DIGIT,Validators.REQUIRE_NON_EMPTY_STRING);
validationPanel.getValidationGroup().add(nameTxt2,Validators.REQUIRE_NON_EMPTY_STRING);
validationPanel.getValidationGroup().add(nameTxt3,Validators.REQUIRE_NON_EMPTY_STRING);
validationPanel.setInnerComponent(panel);
pack();
}
public static void main(String[] args) {
new NBValidator().setVisible(true);
}
}
|
hugoheden
|
Posted: January 04, 2010 17:55 by hugoheden
|
|
@cnish_09 Hi, I think I understand what you mean (though I have not executed your test code). One option is to programmatically ensure that all fields are immediately validated when the UI is instantiated (by calling validationPanel.getValidationGroup().validateAll() or whatever the method is named). This means that error icons are shown in the Name1, Name2 and Name3 fields from the beginning already! (This is logical, since if the fields are empty then there are errors in the fields from the beginning.) Is that an option for you? Or would you prefer that the error icons to not be shown in fields that the user has not yet interacted with? Something like this was discussed in Issue 14, see this comment there from 26 September.. But we didn't really do anything about that. Hmm.. |
Tim Boudreau
|
Posted: January 13, 2010 07:13 by Tim Boudreau
|
|
I had the same thought as Hugo - usually I do @Override public void addNotify() { super.addNotify(); group.validateAll(); } to ensure error messages are shown when the UI is first shown (if you use ValidationPanel it will do this for you). If not done at initialization time, then validation doesn't run until the first user input. Does that solve the problem? We could make it automagic - attach a HierarchyListener to any component being validated. Avoiding this code running multiple times is a little more challenging, since you can nest panels with validation groups - and sometimes that really might be the wrong thing to do. So I'm a little wary of making it too magical, but it could be nice. |
cnish_09
|
Posted: February 02, 2010 19:46 by cnish_09
|
|
Hi Tim, Hugoheden, First things first....thanks for your replies and I am really sorry for the late response.. And coming to the discussion. In response to both your opinion.. I need a facility to remove a component from validation group or remove the validation group with a bunch of components as well. This will help me to control the validation as and when i require for the specific field. In short i require some method like myValidationPanel.getValidationGroup.remove(text1); // Which would remove and stop validating for the particular JtextField by name text1. or some thing like myValidationPanel.getValidationGroup.removeAll(); // which would remove all and stop validatting all the components. Is it possible to bring in such a functionality in this API or is it available already. If you want i will also brief you on scenario's why i require such a functionality. And again thanks a lot to you guys. This API is such an wonderful one.. ![]() Thanks in Advance, Nishanth |
Tim Boudreau
|
Posted: February 03, 2010 21:27 by Tim Boudreau
|
| You'll have this shortly - once I've integrated some of Hugo's changes, you should be able to remove a child validation group from a parent. So just have everything you want to remove owned by the same group, and remove that group of components from the main validation group for the panel. I have the same problem in some NetBeans modules where one dialog can display multiple panels, and the current one is the one that should be validated. |
hugoheden
|
Posted: February 09, 2010 00:02 by hugoheden
|
|
> If you want i will also brief you on scenario's why i require such a functionality. Yes, it would actually be interesting to hear how you're using this. If your use case is supported, it could perhaps be described in documentation etc. And if not, then it'd be interesting to see what the alternatives are -- perhaps there's another way to do what you want, or perhaps we should work on supporting it in the future. |
showing 1 - 9 of 9
Replies: 8 - Last Post: February 09, 2010 00:02
by: hugoheden
by: hugoheden









