0

I would like to know how to show to my user at the top of the page, a history of his navigation. Like this:

home > register > product

And how to implement a back and a forward button in JSF. I read some topics but none of them really explain how to implement these functions. I don't want to use some framework for this, I think this is a simple thing to do, which is not necessary to use framework.

I think it's not a good idea do something with <h:link /> entirely, I'm gonna give you guys an example:

User entering at system:

home > register

the user register himself

home > login > register (there's a link where he/she can register another user)

the correct history would be :

home > login > register

And not

home > register
Community
  • 1
  • 1
Valter Silva
  • 16,446
  • 52
  • 137
  • 218
  • The `` is meant to be used in a loop over all pages visited so far, e.g. ``, as hinted by Luiggi. – BalusC Nov 29 '12 at 14:03

2 Answers2

2

What part of the second answer in your link didn't you understand? Using a LinkedList (a Stack implemented by LinkedList or a Deque implemented by ArrayDeque will do the work) and controlling yourself the push and pop operations must not be hard, also create a section in your page to have these links i.e. implemented by <ui:repeat>.

Anyway, PrimeFaces has solved part of this job with the breadcumb component, even if you don't want to use a third party library for this job, you can give a look at the sources and see how PrimeFaces guys have done this job.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • The second example I understand what you said, but how can I pass the current page to the class so it be able to insert in that linkedlist ? – Valter Silva Nov 29 '12 at 13:29
  • It's available by `#{view.viewId}` in EL or `UIViewRoot#getViewId()` in Java. – BalusC Nov 29 '12 at 14:04
0

If you have each page as its own .xhtml page, then you can just hard code the breadcrumbs. If you want the back button to work well, then in all of your links/buttons you need to add ?faces-redirect=true to your links.

Example

<h:commandLink value="Test" action="blah.xhtml?faces-redirect=true" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Catfish
  • 18,876
  • 54
  • 209
  • 353
  • Well he could use whatever link. I was just demonstrating how to do the redirect. – Catfish Nov 28 '12 at 18:54
  • 1
    Your code does post-redirect-get while just a get was been sufficient in this particular case. See also http://stackoverflow.com/questions/4317684/when-should-i-use-houtputlink-instead-of-hcommandlink/4317723#4317723 – BalusC Nov 28 '12 at 18:55
  • @BalusC, would be better if I had this back and forward button without been hardcore, cause I don't know the user behavior, so it should be something more flexible. – Valter Silva Nov 29 '12 at 13:31