2
votes

I'm new in JSF and not sure about a few fundamental issues.

I found i few ways for defining validation for my input fields, but i'm not sure which is the right way to do it.

I'm using bean validation and jsf validation by using ExtVal.

should I use the validation annotation like @Size , @Length inside my entity bean, or should it be inside the managed bean? what is the diffrence for each option?

This question leads me to a more basic one , that I still don't really understand - I have an entity bean with fields and their setters and getters, also I have a managed bean and a xhtml file with a form that displays the fileds inside inputs.
should I define the same fields with their getters and setters inside the managed bean? and when approaching them from the xhtml file I do it by MBname.FiledName ? or is it better not to create the fields again in the managed bean and approch them from the xhtml by calling MBname.details.FiledName (when details return the object) ? again what is the diffrence for each approch?

Thank's In Advance.

1

1 Answers

4
votes

should I use the validation annotation like @Size , @Length inside my entity bean, or should it be inside the managed bean? what is the diffrence for each option?

Depends on the concrete functional requirement. Key point is: how reuseable should the validation be? If configured at entity level, it's reuseable for all frameworks other than JSF. If configured at JSF level, it's not reuseable for frameworks other than JSF which happen to use the same entity.


should I define the same fields with their getters and setters inside the managed bean? and when approaching them from the xhtml file I do it by MBname.FiledName ? or is it better not to create the fields again in the managed bean and approch them from the xhtml by calling MBname.details.FiledName (when details return the object) ? again what is the diffrence for each approch?

You should not duplicate/expand the data model in the controller. This makes no sense. This is not DRY and is thus only maintenance headache.