-1

Our project uses a Web Application developed using JSF, primefaces, xhtml. Currently user can login and navigate through pages sequentially by clicking on 'action' links, like:-

index.xhtml --> login.xhtml --> classes.xhtml --> students.xhtml --> student_info.xhtml

i.e. first login --> shows the list of classes --> user selects a class --> shows the list of students in that class --> user selects a student --> shows the student info. Each of the pages has its own 'backing bean' classes. They are instantiated as and when the user clicks through the pages. Also, user can navigate back via certain links on each page-- say, from 'student_info' page, he/she can go back to the 'students' page.

Now requirement is: user can directly go to an inner page, say, student_info page by typing an 'url' with additional parameters, ?user=alice,?passwd=xyz, ?class=5, ?studentRollNo=15.

Also, the user should still be able to navigate back to other pages (i.e. once the page is opened, their should be no behavior difference whether the user navigated normally to student_info page or, whether he directly provided url with parameters).

My questions are:-

  • How to read url parameters in JSF?
  • Which page (or backing bean) should handle the parameters? Should it be done centrally, or, in each page (backing bean) ?
  • In case each page handles its relevant parameters only -- is there way to redirect remaining parameters to the next page ?
  • What are the best practices used in such implementations?

Note:

  • Actual web application is much more complex, tried to provide a simpler picture which pinpoints my problem.
  • new to JSF, Web App etc. Don't know if there are some JSF terminologies to describe above issues.
Tarik
  • 4,961
  • 3
  • 36
  • 67
Siddhartha Ghosh
  • 2,988
  • 5
  • 18
  • 25
  • 1
    possible duplicate of [How get GET parameters with JSF2?](http://stackoverflow.com/questions/7775179/how-get-get-parameters-with-jsf2) – Tarik Feb 24 '15 at 18:43
  • see also http://stackoverflow.com/questions/3355611/parameter-in-url-jsf2 and http://stackoverflow.com/questions/10724428/how-do-i-process-get-query-string-url-parameters-in-backing-bean-on-page-load – Tarik Feb 24 '15 at 18:44

1 Answers1

0

you can pass it by url request, and each BackingBean handle it
ex: mypage.xhtml?myparam=test

and inject the HttpServletRequest in your BackingBean (if you are using CDI)

@Inject
HttpServletRequest request;

and get the param

@PostConstruct
public void init() {
    String myparam = request.getParameter("myParam");     
}

for redirect to other page you can use

public String redirect() {
    return "otherPage.xhtml?faces-redirect=true&otherParam=test";
}
Rafael Zeffa
  • 2,334
  • 22
  • 20
  • please improve the formatting of your answer, use "//" for comments inside the code. But, better you to not include them in code as they don't appear as comments – Tarik Feb 24 '15 at 18:45