java 为什么 p:panelGrid 不能与 ui:repeat 一起使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12972576/
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
Why does p:panelGrid not work with ui:repeat?
提问by Zaw Than oo
If I use as below, I get no error, no output.
Why does p:panelGrid
not work with ui:repeat
?
如果我按如下方式使用,则不会出现错误,也没有输出。为什么不p:panelGrid
工作ui:repeat
?
Note: I don't want to use c:forEach
because of the I already face a lot of JSF issue.
注意:我不想使用,c:forEach
因为我已经面临很多 JSF 问题。
<p:panelGrid>
<ui:repeat value="#{MyBean.dataList}" var="data">
<p:row>
<p:column>
<h:outputText value="#{data.name}"/>
</p:column>
<p:column>
<h:outputText value="#{data.description}"/>
</p:column>
</p:row>
</ui:repeat>
</p:panelGrid>
MyBean.java
我的Bean.java
public List<Data> getDataList(){
List<Data> result = new ArrayList<Data>();
result.add(new Data("Name 1", "Description 1"));
result.add(new Data("Name 2", "Description 2"));
result.add(new Data("Name 3", "Description 3"));
result.add(new Data("Name 4", "Description 4"));
return result;
}
Expected output with primefaces
素面的预期输出
回答by Joeri Hendrickx
ui:repeat
will not work because it does not actually add components to the component tree.
ui:repeat
将不起作用,因为它实际上并未将组件添加到组件树中。
ui:repeat
only works during the render phase, and rerenders its child components multiple times with different state.
ui:repeat
仅在渲染阶段工作,并以不同的状态多次重新渲染其子组件。
Some components, such as panelgrid
, but also datatable
, expect to have certain children in the component tree in order to work correctly. Since ui:repeat
does not add these, this approach does not work.
某些组件,例如panelgrid
, 和datatable
,希望在组件树中具有某些子组件才能正常工作。由于ui:repeat
不添加这些,这种方法不起作用。
I'm sorry, but the normal solution for this is to use c:foreach
, which doesadd children to the tree.
我很抱歉,但通常的解决方案是使用c:foreach
,它确实将孩子添加到树中。
See http://www.ninthavenue.com.au/blog/c:foreach-vs-ui:repeat-in-facelets
见http://www.ninthavenue.com.au/blog/c:foreach-vs-ui:repeat-in-facelets
回答by khan
Try it by defining columns
in p:panelGrid
as you have static number columns then you should have to define <p:panelGrid columns="">
.It will work.
But I suggest you to use primefaces datatable
for this
通过定义columns
inp:panelGrid
来尝试它,因为您有静态数字列,那么您应该必须定义。<p:panelGrid columns="">
它会起作用。
但我建议你使用primefaces datatable
这个
<p:dataTable id="availableCars" var="car" value="#{tableBean.carsSmall}">
<p:column style="width:20px">
<h:outputText id="dragIcon"
styleClass="ui-icon ui-icon-arrow-4" />
<p:draggable for="dragIcon" revert="true" />
</p:column>
<p:column headerText="Model">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Manufacturer">
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>
Here is the linkfrom where you can find this code and primnefaces showcase.I think it will fulfill your requirment