开发者

Java - Recommended Ways for Validation of Blank Entries

Good day!

I am new to programming esp. JAVA and I have a problem regarding a validation. I want to create a validation wherein blank entries will not be accepted. So if i call this code:

entry[i].setName(JOptionPane.showInputDialog("Enter Name: "));

if the entry is blank, it will not be accepted and an error will prompt:

Cannot accept blank entries!

Of course it could easily remedied by doing this code:

 String name = JOptionPane.showInputDialog("Enter Name: ");
 while (name.equals("")){
       JOptionPane.showMessageDialog(null, "Cannot accept blank entries!");
       name = JOptionPane.show开发者_如何学GoInputDialog("Enter Name: ");
 }

but if i want to validate 100 fields that i don't want to have a blank entries, then my code will be messy and long...

So how could I do it better? I've read about using getters and setters or the try-catch methods to do the validation but I don't know if this kind of validation is applicable. And I don't know HOW TO DO IT. (iam not very experienced in programming) And if it is applicable, would I be violating the Model-View-Controller concept if I included an JOption message dialog box on my getter and setter methods? What codes do programmers usually do in doing blank entries validation???

Your opinion will be highly appreciated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜