我得到了一个包含步骤的列表,显示如下:
<ul >
<for:forEach id="steps" items="#{RecipeBean.recipe.steps}" var="step">
<li> <com:Step description="#{step.stepDescription}"/></li>
</for:forEach>
</ul>
<p:commandButton id="addstep" value="#{msg['step.add']}" action="#{RecipeBean.addStep}" update="steps" />
按钮addStep将一个步骤添加到RecipeBean.recipe.steps集合中。现在应该显示新添加的步骤。但就像这样,我收到错误消息 Cannot find component withidentifier“steps”引用自“j_idt8:addstep”,这可能是 for:forEach 组件。
有人知道我该如何解决这个问题吗?
最佳答案
update
<p:commandButton>
的属性组件应该指向一个组件。自 <for:forEach>
不是组件,而是标记处理程序,您会收到一条错误消息。
我建议您查看现有的 PrimeFaces 组件,例如 DataList ,它以无序格式呈现一个列表对象。
然后,您可以按如下方式重构代码:
<p:dataList id="steps" items="#{RecipeBean.recipe.steps}"
var="step" itemType="disc">
<com:Step description="#{step.stepDescription}" />
</p:dataList>
<p:commandButton id="addstep" value="#{msg['step.add']}"
action="#{RecipeBean.addStep}" update="steps" />
关于jsf - 如何更新/渲染<:forEach with ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19078570/