JSF with Prettyfaces navigation -
I am using JSF 2.2 with PrettyFaces 3.3.3 in my Entreprise application.
I am thinking that the way I handle navigation is correct (AdminCompaniesController.java):
@ManagedBean (name = "companiesBean") @ViewScoped @URLMappings (mappings = {@URLMapping (id = "admin-companies-view", pattern = "/ admin / company / view / # {id}", viewId = "/ admin / companyView.jsf"), @URLMapping ( Id = "admin-companies-view", pattern = "/ admin / company / edit / # {id}", viewId = "/ admin / companyEdit.jsf"), @URLMapping (ID = "admin-companies-add ", Pattern =" / admin / company / add ", viewId =" /admin/companyAdd.jsf "), @URLMapping (id =" admin-companies " A. List "pattern =" / admin / companies ", viewId =" /admin/companies.jsf ")}) public class administrator Consulting controller executes Siriyliz qualified {@EJB private Kanpanisewa Kanpanisewa; Private collection & lt; Company & gt; Companies = new arreelist & lt; & Gt; (); Private company company; @PostConstruct Public Zero init () {string viewId = NavigationUtils.getViewId (); Switch (view ID) {case ("admin-companies-list"): companies = company services. break; Cases ("admin-companies-add"): company = new company (); break; Case ("admin-companies-view"): case ("admin-companies-edit"): Long ID = NavigationTotal .getParameter ("id", long.class); Company = companyService.getCompanyById (ID); break; }}
I am using PrettyFaces parameter from annotation:
NavigationTotal: .getViewId ()
equals PrettyContext .getCurrentInstance () .getCurrentMapping (). GetId ()
and from url:
NavigationTotal .getParameter ("id", long.class)
FacesContext.getCurrentInstance () Is equivalent to. GetExternalContext (). GetRequestParameterMap (). Get ("id")
Is this the correct way to manage CRUD operations? My unit "company"? I've read about the OCPSoft documentation () about @URLQuery parameter
and @RockTracker
, but I'm not sure how to implement them instead of my switch / case solution. As the @chalk says:
Think about using the bean. Every mapping that basically means that you will end up with a square of each page. IMHO makes it completely understandable. Your current approach seems to be that you keep God class Are there.
The above suggestion is good practice, and stops the requirement of a case statement, because each @URLMapping
- the annotated bean has its own clear @Razaon
or @PostConstruct
will be the method. Additionally, you can use direct injection to pass parameters values to those beans without using the request parameter:
@URLMapping (id = "Admin-companies-view", pattern = "/ admin / company / view / # {id: pageBean.id}", ViewId = "/admin/companyView.jsf")
Comments
Post a Comment