Bean population

Print

 

Method input Bean population is one of the key features Javajax was born for. When you use the received method parameters to populate manually a Bean, it is definitely faster ask the framework to do the job for you. 
Here is an example:

You have the following method: 

protected Response saveUserInfo(@Param("name") String name
, @Param("surname") String surname
, @Param("street") String street
, @Param("city") String city) {
UserBean userBean = new UserBean();
userBean.setName(name);
userBean.setSurname(surname);
userBean.getAddress().setStreet(street);
userBean.getAddress().setCity(city);

... }


The same method can be written this way:

protected Response saveUserInfo(@Populate(params={@Param("name")
, @Param("surname")
, @Param("street")
, @Param("city")}
, attrs={"name","surname","address.street","address.city"})
UserBean userBean) {
... }

where attrs is the list of bean attributes that will be mapped with parameters.
This list is optional if request parameter names are equal to bean attribute names.
Now you have the input parameter userBean populated with values received on the request object.
You can also add a post-population validation step with expressions: 

expressions={@Expression("bean.address.city != bean.address.street")}