Bean Population

If your input parameter is a Bean, JavAjax can populate its attributes with values received in the request through the annotation @Bean, which can be configured with an array of @Param annotations.
This way, data conversion and validation for bean population follow the same rules used with @Param annotation.

protected Response createUser(
  @Bean(params={
    @Param(value="userId", mandatory=true)
    , @Param(value="email" attributeName="emailAddress")
}) BeanUser user) {
  ...
}

@Bean annotation can also be used within a @ParameterMapping annotation:

@ParameterMapping(
  beans={
  @Bean(params={
    @Param(value="userId", mandatory=true)
    , @Param(value="email" attributeName="emailAddress")
  })
})
protected Response createUser(BeanUser user) {
  ...
}

Moreover, if the bean attribute is also a bean, it can be recursively populated:

@ParameterMapping(
  beans={
  @Bean(params={
    @Param(value="userId", mandatory=true)
    , @Param(value="name")
    , @Param(value="surname")
    , @Param(value="email" attributeName="emailAddress")
    , @Param(value="country" attributeName="country.id")
  })
})
protected Response createUser(BeanUser user) {
  ...
}

where "country" parameter will be set to "id" attribute of the bean country. It is equivalent to user.getCountry().setId(country)

Pre-population strategy

In some cases you want the framework to use a pre-populated bean instead of a new instance, so that when your method is called it receives not only the values read from the request, but also all the other attributes of the entity. A typical scenario is during a partial update operation, you need a bean completely populated, not only with parameters read from the request. You can achieve this specifying a @Factory, which can be configured to: The resulting bean will then be populated by the framework with the values received from the request.

Strategy.ACTION_METHOD example:
@ParameterMapping(
  beans={
    @Bean(
    params={
      @Param(value="email", mandatory=true)
      , @Param(value="address", mandatory=true)
    },
    factory=@Factory(
      value="readUser",
      strategy=Strategy.ACTION_METHOD,
      params={@Param("userId")})
      )
    }
  )
protected Response updateUser(BeanUser user) {
  ...
}

private BeanUser readUser(String userId) {
  ...
}

Strategy.SPRING_INJECTION example:
@ParameterMapping(
  beans={
    @Bean(
    params={
      @Param(value="email", mandatory=true)
      , @Param(value="address", mandatory=true)
    },
    factory=@Factory(
      value="beans/MyBeanUser",
      strategy=Strategy.SPRING_INJECTION)
      )
    }
  )
protected Response updateUser(BeanUser user) {
  ...
}

When updateUser method is called, Javajax, instead of instantiating a new BeanUser, applies the Factory method specified to obtain the Bean, then populates it with email and address received in the request (and any other appliable parameter) and pass it to the updateUser method.

Post-population validation

@Bean annotation offers also another validation step, performed through expressions written in Jexl language. This step gives you the ability to validate your Bean after it has been populated, to perform additional checks before the method is actually invoked.

@ParameterMapping(
  beans={
  @Bean(params={
    @Param(value="userId", mandatory=true)
    , @Param(value="password", mandatory=true)
    , @Param(value="confirmPassword", mandatory=true)
  }, expressions={@Expression(value="bean.password == bean.confirmPassword", messageKey="error.pwd.dont.match")})
})
protected Response createUser(BeanUser user) {
  ...
}

In the example, the expression will check that password and confirmPassword attributes are equal. If they are not equal, a validation error is generated using the specified message key "error.pwd.dont.match".