[hibernate-issues] [Hibernate-JIRA] Commented: (BVAL-267) Provide a ConstraintViolationException builder to facilitate consumer code

Antonio Goncalves (JIRA) noreply at atlassian.com
Sun Feb 26 17:24:50 EST 2012


    [ https://hibernate.onjira.com/browse/BVAL-267?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45693#comment-45693 ] 

Antonio Goncalves commented on BVAL-267:
----------------------------------------

After a quick Tweet about facilitating the creation of {{ConstraintViolationException}}, Emmanuel suggested that I explain myself a bit longer (https://twitter.com/emmanuelbernard/status/173884950544777217). So here I go.


Not all the constraints can be expressed with annotations. Some business constraints follow complex workflows that BV cannot help with. In such cases, we end up using our own exception : 

{code}
if (complexBusinessConstraint)
  throw new ComplexBusinessException("A complex business constraint has been violated");
{code} 

In a typical EJB/JSF world we then have to catch this exception and use the {{FacesContext}} to add a {{FacesMessage}} so it can be displayed to the user. It would be nice if we could use the BV/JSF integration and do something like that so a simple message is automatically displayed (or resource bundle) :

{code}
if (complexBusinessConstraint)
  throw new ConstraintViolationException("A complex business constraint has been violated");
{code} 

This way we don't have to try to tweek a  {{Set<ConstraintViolation<?>>}} (which is the constructor of {{ConstraintViolationException}}) or play with the {{ConstraintValidatorContext}} to build a constraint violation.

So really the title of this JIRA should be _Provide a ConstraintViolationException constructor to facilitate JSF integration_ (or something like that).

> Provide a ConstraintViolationException builder to facilitate consumer code
> --------------------------------------------------------------------------
>
>                 Key: BVAL-267
>                 URL: https://hibernate.onjira.com/browse/BVAL-267
>             Project: Bean Validation
>          Issue Type: Improvement
>          Components: spec-general
>            Reporter: Emmanuel Bernard
>


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list