问题描述
我无法呈现素面的 breadcrumb 控件.我正在使用ui:repeat动态构建面包屑.将其包装在 p:breadCrumb 标记中的那一刻,我无法在页面上看到该控件
I am not able to render the breadcrumb control of primefaces. I am dynamically building the breadcrumb using ui:repeat. The moment I wrapped it inside the p:breadCrumb tag , I am not able to see the control on the page
以下是我在.xhtml中使用的代码
Following code I am using in my .xhtml
<p:breadCrumb>
<ui:repeat value="#{conversationScope.trail}" var="bcrumb">
<h:outputLink value="#{bcrumb.url}">
<h:outputText value="#{bcrumb.label}" />
<h:outputText value=">" />
</h:outputLink>
<p:menuitem value="#{bcrumb.label}" url="#{bcrumb.url}" />
</ui:repeat>
</p:breadCrumb>
请建议有其他选择吗?
推荐答案
要在PrimeFaces中动态构建<p:breadCrumb>
菜单,您需要在bean中使用MenuModel对象来渲染BreadCrumb组件.遍历跟踪列表,创建MenuItems并将其添加为MenuModel对象.
To build a <p:breadCrumb>
menu in PrimeFaces dynamically you'll want to use a MenuModel object in your bean for the breadCrumb component to render. Loop through your trail list creating MenuItems and add them the MenuModel object.
在您的.xhtml
<p:breadCrumb model="#{crumbBean.model}" />
将菜单项添加到面包屑菜单的Bean.
Bean to add menu items to the breadcrumb menu.
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.primefaces.component.menuitem.MenuItem;
import org.primefaces.model.DefaultMenuModel;
import org.primefaces.model.MenuModel;
@ManagedBean
@RequestScoped
public class CrumbBean {
private MenuModel model;
public CrumbBean() {
model = new DefaultMenuModel();
MenuItem item1 = new MenuItem();
item1.setValue("First");
item1.setUrl("#");
model.addMenuItem(item1);
MenuItem item2 = new MenuItem();
item2.setValue("Second");
item2.setUrl("#");
model.addMenuItem(item2);
}
public MenuModel getModel() {
return model;
}
}
这篇关于primefaces面包屑不能与ui:repeat一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!