Showing posts with label beans. Show all posts
Showing posts with label beans. Show all posts

Thursday, 17 November 2022

Java Beans

Back when I was young and innocent, and when I started learning about Beans. Java Beans, Java Bean Conventions, EJB Beans, and all that, I started writing Beans.

So I ended up with a lot of classes called ItemsBean, UsersBean, etc.

I visited this admittedly old code, and immediately thought, "What was I thinking?!?".

A Bean, though most veteran Java Programmers have an incling what it is, does not provide ANY meaning to people outside the Java field. Even for Java people, it doesn't explain a lot.

This is a naming scheme where a lot of people completely got it wrong.

Sure, Beans is cute and funny in combination with Java (coffee, in case I have to spell it out.)

So, paraphrasing Uncle Bob here:

“Don't be cute.”
- Uncle Bob (Robert C. Martin)

Unfortunately, we're kinda stuck with the naming scheme for now. I will just point everyone to the magical file "beans.xml" that is supposed to just exist in a certain place, to make magic happen.

Don't get me wrong. I love Java. But, admittedly, sometimes it's weird...

References

Clean Code - Chapter 2 - Meaningful Names (Robert C. Martin)
http://cleancoder.com/

Thursday, 4 February 2016

Validation of Beans

Just a small utility function that prints out readable messages on what is wrong with a certain bean (like for example a JPA Entity).

Got a little miffed with the fact that my javax.validation.ConstraintViolationException that is thrown, never shows the exact problem. I always have to drill down into the Exception to find the message in order to fix the problem.

I hope it helps someone.

See for more information about bean validation JSR 303.

References

The Java EE 6 Tutorial - Using Bean Validation
http://docs.oracle.com/javaee/6/tutorial/doc/gircz.html
The Java EE 6 Tutorial - Validating Persistent Fields and Properties
https://docs.oracle.com/cd/E19798-01/821-1841/gkahq/index.html