java - Best Practice In JSF for Forms, Datatables, etc -


should have bean every form, datatable etc in jsf?

for example, have form registration, has 2 fields , button are: nickname, password, submit

should submitting form go registirationformbean or somewhere in userbean or userservicebean?

what best practice?

thank you.

to decide whether or not should create @managedbean exclusively component of page (e.g. form, datatable), believe should think modularity of design.

the 1st question should ask is: will component re-used in many pages?. example, on sensitive pages such changepassword or deleteaccount, usually, ask user enter current password validate identity before performing logic. in case, should have exclusive bean validating password component can re-use component again , again without having re-code validating function every time.

secondly, use @managedbean place hold related functions work toward same goal. grouping of functions can pretty subjective. example, can have page called createproduct.xhtml bean called createproductbean has functions creating product. in case, it's 1 bean per view. way have bean called productmanager has functions related product object (i.e. create, read, update, remove). in case, it's 1 bean many views (e.g. createproduct.xhtml, removeproduct.xhtml). ease of future maintenance , division of work, use 1 bean per view. 2nd approach 1 bean many views on situations cannot think of example yet :p... update answer when got 1 ;).

thirdly, prefer follow 3-tier mvc model , separate back-end logic away front-end. example, persist new account in database, inject @ejb or @webserviceref ask back-end system perform necessary logic. it's more maintenance friendly in future :).

so, using registeraccount example, have

  • 1 bean called userexistencevalidator check if nickname exists in database. during registration, can throw error if user chooses nickname taken. can use bean check if user exists in addfriend.xhtml page.
  • another bean called registirationformbean capture user's inputs , talk back-end persist new account.

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -