ui:repeat-从列表中添加/删除元素无法正常工作 [英] ui:repeat - adding / removing elements from list does not work properly
问题描述
我的.xhtml文件中包含以下代码
I have following code in my .xhtml file
<h:form id="registration3Form">
<h:panelGroup id="terms_outer_panel">
<h:commandLink styleClass="item-7"
action="#{registerBusinessWizardController.addCourse}"
value="#{msgBundle['registerThirdPage.panel.addSchedule']}">
</h:commandLink>
<ui:repeat value="#{registerBusinessWizardController.courses}" var="course">
<h:panelGroup id="terms_inner_panel">
<div class="term">
<h:inputText id="price" styleClass="item-2" value="#{course.price}" />
<h:inputText id="dateFrom" styleClass="date" value="#{course.date}" >
<f:convertDateTime pattern="yy-MM-dd" type="date" dateStyle="long"/>
</h:inputText>
<h:inputTextarea value="#{course.additionalInfo}"/>
<p class="more">
<h:commandLink
value="#{msgBundle['registerThirdPage.panel.deleteSchedule']}"
actionListener="#{registerBusinessWizardController.removeCourse}">
<f:ajax render=":registration3Form:terms_outer_panel" execute="terms_inner_panel"/>
</h:commandLink>
</p>
</div>
</h:panelGroup>
</ui:repeat>
//some other stuff
</h:panelGroup>
</h:form>
并且呈现页面时.并且用户单击addSchedule链接,我希望ui重复将添加新的div class ="term" 空值绑定到输入,因为:
And when page is rendered. And user clicks addSchedule link I expect that ui repeat will add new div class="term" with empty values bind to inputs, because:
public void addCourse(){
Course course = new Course();
courses.add(course);
}
我要向ui:repeat使用的列表中添加价格为null附加信息和日期为空的新Course对象.
I am adding new Course object with null price additionalInfo and date to the list used by ui:repeat.
相反,我得到了新的
<div class="term">
部分具有从上一个条目复制的值.
part with values copied from previous entry.
当我从列表中删除元素时(在managedBean中,列表中的适当对象也被删除),我看到刚被删除的对象中的数据:/
When I remove element from list (In managedBean proper object from list is removed) I see data from object which was just removed :/
有人遇到过这种问题吗? 您有什么建议吗?
Did someone encounter this kind of problem? Do you have any advice?
推荐答案
这似乎是另一个<ui:repeat>
错误. Mojarra的<ui:repeat>
有太多问题.第一步是通过使用完全有价值的UIData
组件(例如<h:dataTable>
)来替换该组件,以免被怀疑.如果有效,则绝对是<ui:repeat>
中的错误,否则仅是您自己的代码中的错误(基于到目前为止给出的代码,我看不到任何错误,但是我假设您的bean是@ViewScoped
) .
This seems to be another <ui:repeat>
bug. Mojarra's <ui:repeat>
has (had) too many problems. First step is to exclude the component from being suspect by replacing it by a fullworthy UIData
component, such as <h:dataTable>
. If it works, then it's most definitely a bug in <ui:repeat>
, otherwise it's just a bug in your own code (based on the code given as far I don't see any, I however assume that your bean is @ViewScoped
).
如果确实是由<ui:repeat>
本身引起的,那么第一步通常是升级到最新的Mojarra版本.当前是 2.0.6(对于Servlet 2.5容器)和2.1.4(对于Servlet 3.0容器).如果仍不能解决问题,则应考虑使用 MyFaces 替换Mojarra,它具有不同的效果和更好的<ui:repeat>
实现.如果由于某种原因这不是一个选择,那么您应该考虑查看一个第三方组件库,该库具有一个基于UIData
的组件,该组件不会呈现任何标记,例如
If it's indeed caused by <ui:repeat>
itself, then the first step is usually to upgrade to latest Mojarra version. This is currently 2.0.6 for Servlet 2.5 containers and 2.1.4 for Servlet 3.0 containers. If that doesn't solve the problem, then you should look at replacing Mojarra by MyFaces which has a different and better <ui:repeat>
implementation. If that isn't an option for some reason, then you should consider looking at a 3rd party component library which has an UIData
based component which doesn't render any markup, such as Tomahawk's <t:dataList>
.
这篇关于ui:repeat-从列表中添加/删除元素无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!