How to convert a Java object (bean) to key-value pairs (and vice versa)?

Lots of potential solutions, but let’s add just one more. Use Jackson (JSON processing lib) to do “json-less” conversion, like: ObjectMapper m = new ObjectMapper(); Map<String,Object> props = m.convertValue(myBean, Map.class); MyBean anotherBean = m.convertValue(props, MyBean.class); (this blog entry has some more examples) You can basically convert any compatible types: compatible meaning that if you did … Read more

What is java pojo class, java bean, normal class? [duplicate]

Normal Class: A Java class Java Beans: All properties private (use getters/setters) A public no-argument constructor Implements Serializable. Pojo: Plain Old Java Object is a Java object not bound by any restriction other than those forced by the Java Language Specification. I.e., a POJO should not have to Extend prespecified classes Implement prespecified interface Contain … Read more

JavaBean wrapping with JavaFX Properties

The Simple*Property classes are full, standalone implementations of their corresponding Property abstract classes, and do not rely on any other object. So, for example, SimpleStringProperty contains a (private) String field itself which holds the current value of the property. The parameters to the constructor you showed: new SimpleStringProperty(bean, “name”) are: bean: the bean to which … Read more

How to perform validation in JSF, how to create a custom validator in JSF

The standard way is to implement the Validator interface. @FacesValidator(“fooValidator”) public class FooValidator implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { // … if (valueIsInvalid) { throw new ValidatorException(new FacesMessage(“Value is invalid!”)); } } } The @FacesValidator will register it to JSF with validator ID myValidator so that … Read more

Can I update a JSF component from a JSF backing bean method?

Using standard JSF API, add the client ID to PartialViewContext#getRenderIds(). FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(“foo:bar”); Using PrimeFaces specific API, use PrimeFaces.Ajax#update(). PrimeFaces.current().ajax().update(“foo:bar”); Or if you’re not on PrimeFaces 6.2+ yet, use RequestContext#update(). RequestContext.getCurrentInstance().update(“foo:bar”); If you happen to use JSF utility library OmniFaces, use Ajax#update(). Ajax.update(“foo:bar”); Regardless of the way, note that those client IDs should represent absolute client IDs … Read more

Places where JavaBeans are used?

They often just represents real world data. Here’s a simple example of a Javabean: public class User implements java.io.Serializable { // Properties. private Long id; private String name; private Date birthdate; // Getters. public Long getId() { return id; } public String getName() { return name; } public Date getBirthdate() { return birthdate; } // … Read more

javax.el.PropertyNotFoundException: Property ‘foo’ not found on type com.example.Bean

javax.el.PropertyNotFoundException: Property ‘foo’ not found on type com.example.Bean This literally means that the mentioned class com.example.Bean doesn’t have a public (non-static!) getter method for the mentioned property foo. Note that the field itself is irrelevant here! The public getter method name must start with get, followed by the property name which is capitalized at only … Read more