java Primefaces UI:重复不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14334777/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Primefaces UI:repeat not working
提问by sampathpremarathna
I'm trying to create accordionPanel in Primefaces.And i'm trying to create that using ui:repeat
so i can create panel tabs dynamically.But somehow my code doesn't works, accordionPanel is empty and does not have any tabs.can any one give me the reason or point me how to achieve this.
我正在尝试在 Primefaces 中创建手风琴面板。我正在尝试创建它,ui:repeat
以便我可以动态创建面板选项卡。但不知何故我的代码不起作用,手风琴面板是空的,没有任何选项卡。任何人都可以给我的原因或指出我如何实现这一点。
here my bean.
这是我的豆。
@ManagedBean(name = "divisionList")
public class Divisions implements Serializable {
private List<String> divStrings;
public List<String> getDivStrings() {
return divStrings;
}
public Divisions(){
divStrings=new ArrayList<String>();
divStrings.add("Division A") ;
divStrings.add("Division B");
}
}
and in my xhtml :
在我的 xhtml 中:
<p:accordionPanel >
<ui:repeat value="#{divisionList.divStrings}" var="divis">
<p:tab title="#{divis}">
Content
</p:tab>
</ui:repeat>
</p:accordionPanel>
EDIT:
编辑:
But when it print like this its working :O
但是当它像这样打印时它的工作:O
<ui:repeat value="#{divisionList.divStrings}" var="divis">
<h:outputText value="#{divis}" />
</ui:repeat>
回答by roel
There is no problem with your ui:repeat, don't wrap it inside an empty
你的 ui 没有问题:重复,不要把它包在一个空的里面
<p:accordionPanel >
Or remove the uirepeat and fill in the value of your accordionPanel
或者删除uirepeat并填写您的手风琴面板的值
Do like this
这样做
<p:accordionPanel value="#{test.divStrings}" var="divis" >
<p:tab title="#{divis}">
Content
</p:tab>
</p:accordionPanel>
回答by Gimby
In stead of initializing the list in the constructor, try initializing it in a @PostConstruct annotated method.
不要在构造函数中初始化列表,而是尝试在 @PostConstruct 注释方法中初始化它。
@PostConstruct
public void init(){
divStrings=new ArrayList<String>();
divStrings.add("Division A");
divStrings.add("Division B");
}