VwpFAQlinkinbreadcrumbs
How can I dynamically generate and add a set of links to a Breadcrumb on my jsf page?
The documentation in Netbeans Visual Web Pack says that the links in the bread crumb can be added by an array of Hyperlink objects. I can create the Hyperlink array and assign it to the Breadcrumb just fine, but I'm having problems trying to set the action of the Hyperlink.
In an application that based on J2EE 1.4, an issue has been found with the setPages call of bread crumbs which prevents the action handler from being called.
To workaround this issue, you need to replace the setPages call with folderCrumbs.getChildren().add(hyperTmp) to add the hyperlink as a child of the Breadcrumbs. This will make the action handler to get invoked.
Hyperlink[[ | ]] crumbsTest = new Hyperlink[5]; for (int i = 0; i < 5; i++) { Hyperlink hyperTmp = new Hyperlink(); hyperTmp.setText("Link " + i); hyperTmp.setToolTip("Link " + i + " tooltip"); //create the methodbind MethodBinding mb = (MethodBinding) this.getApplication().createMethodBinding("#{Page1.breadcrumbLinkTest_action}", null); hyperTmp.setAction(mb); crumbsTest[I] = hyperTmp; folderCrumbs.getChildren().add(hyperTmp); }
If your application is based on Java EE 5, you can use setPages. Please note the way to define method binding is different.
Hyperlink[[ | ]] crumbsTest = new Hyperlink[5]; for (int i = 0; i < 5; i++) { Hyperlink hyperTmp = new Hyperlink(); hyperTmp.setText("Link " + i); hyperTmp.setToolTip("Link " + i + " tooltip"); // Create method expression MethodExpression me = (MethodExpression)this.getApplication().getExpressionFactory().createMethodExpression( getFacesContext().getELContext(), "#{Page1.breadcrumbLinkTest_action}", String.class,new Class[] {}); hyperTmp.setActionExpression(me); crumbsTest[I] = hyperTmp; } breadcrumbs1.setPages(crumbsTest);