Dynamic BreadCrumbs

UI Components for JSF
Post Reply
shaikoren
Posts: 4
Joined: 15 Sep 2010, 17:28

27 Jan 2011, 16:33

Hi

We are trying to use breadcrumbs component but cannot see from the examples how the current pages are updated dynamically.

I see there was a similar post last wee but could not find any info in the documentation (user guide and javadoc).

Could anyone please point to a sample where the model attribute is used and the breadcrumbs are updated as user navigates? Or is this somethig that doesnt come with the library and is up to developers to implement?

Thanks
Shai
PrimeFaces 2.2.RC2, Mojarra 2.0.3, Weblogic 10.3.3,

User avatar
Aleph06
Posts: 1
Joined: 27 Jan 2011, 19:04

28 Jan 2011, 04:10

Hi shaikoren.

the pages doesn't add automatically, if you've check out the documentation you've seen than for a dynamic behavior you should create a MenuModel in a backing beans and every time you redirect to other page perform a method to add. it would be something like this: (Sorry for my bad english)

Code: Select all

<p:breadCrumb model="#{BreadCrumbController.breadcrumbmodel}"/>
And in your controller

Code: Select all

public class BreadCrumbController {
 
 public BreadCrumbController () {
     MenuItem item = new MenuItem();
        item.setValue("Home");
        item.setUrl("/faces/index.xhtml");
        item.setId("mithome");
 this.breadcrumbmodel.addMenuItem(item);   
 }

 private MenuModel breadcrumbmodel;
.. getters and setters

 public void AddItem(String value, String url, String id){
  MenuItem item = new MenuItem();
        item.setValue(value);
        item.setUrl(url);
        item.setId(id);
  this.breadcrumbmodel.addMenuItem(item);
  }
}
hope it helps.

Primefaces - 2.2RC2
Mojarra 2.0.2
JSF 2.0
Tomcat 6.0.20

shaikoren
Posts: 4
Joined: 15 Sep 2010, 17:28

28 Jan 2011, 19:04

Hi Alef

Thanks, that does help. It is exactly what we were hoping to do (as oppose to repeat around the menuItems as in most examples), which suggests the problem might be elsewhere (getting NullPointerException at com.sun.faces.lifecycle.RestoreViewPhase.notifyAfter(RestoreViewPhase.java:288). It might be related to a potential mojarra bug: http://ocpsoft.com/support/topic/except ... dling-jsf2. Will try version 2.0.4 and see. Will update if this is the problem.

Also your post confirms we needed to keep track on the pages as we navigate a long, which I was not sure. The source for BreadCrumb in version 2.0.2 had the listener:
@ListenerFor(systemEventClass = PostAddToViewEvent.class), so I was hoping for it to do the magic.


Thanks again

Shai
PrimeFaces 2.2.RC2, Mojarra 2.0.3, Weblogic 10.3.3,

anavarro
Posts: 20
Joined: 14 Aug 2012, 01:06

28 Aug 2012, 20:00

Aleph06 wrote:Hi shaikoren.

the pages doesn't add automatically, if you've check out the documentation you've seen than for a dynamic behavior you should create a MenuModel in a backing beans and every time you redirect to other page perform a method to add. it would be something like this: (Sorry for my bad english)

Code: Select all

<p:breadCrumb model="#{BreadCrumbController.breadcrumbmodel}"/>
And in your controller

Code: Select all

public class BreadCrumbController {
 
 public BreadCrumbController () {
     MenuItem item = new MenuItem();
        item.setValue("Home");
        item.setUrl("/faces/index.xhtml");
        item.setId("mithome");
 this.breadcrumbmodel.addMenuItem(item);   
 }

 private MenuModel breadcrumbmodel;
.. getters and setters

 public void AddItem(String value, String url, String id){
  MenuItem item = new MenuItem();
        item.setValue(value);
        item.setUrl(url);
        item.setId(id);
  this.breadcrumbmodel.addMenuItem(item);
  }
}
hope it helps.

ALL that code has to go in the controller?

then what goes in the model??

thanks
JSF 2.1
Primefaces 2.2.1
Netbeans 7.1.2
Apache Tomcat 7.0.22.0

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 40 guests