model view controller - Implementing a Registiration Form with JSF? -


i trying learn web development jsf myself. there planty of sources learn , having hard time binding them together.

imagine have database table called user have columns: id, name, surname. using jpa in project have class @entity annotation, mapped class. have index.xhtml, in have registiration form username , password fields. when user clicks register button, should check if user same username exists, if not, should register user , redirct user welcome.xhtml. if registiration unsuccessful, user should stay in index.xhtml.

my questions are:

i have index.xhtml, , userentity.java. else? need registirationformbean @managedbean? , registirationformbean have registeruser method with. what? have registirationformcontrollerbean? should managedbean well? or need userregistirationbean? userregistirationservice?

so how create mvc properly?

you need 1 bean - there caveat, shouldn't use managedbean annotation anymore , move forward cdi technology, use @named. have getter , setter entity can work on page. , registration method, ti can like

@named //@requestscoped default public class mybean {      @inject //you can inject other beans or ejbs     private userdao userdao; //this class handle db operations user      private youruserentity entity;      public void register() {         if(!userdao.isuserexists(entity)) {             userdao.save(entity);         }     } } 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -