【发布时间】:2010-06-03 17:22:54
【问题描述】:
是否有任何方法可以将 JSF2.0 与可变组件列表结合使用?例如,假设我列出了我想编辑的人。它们在页面上显示为组件 PersonEditor 的列表,允许更改人员数据。每个编辑器都与单个 Person 元素相关联。为了使其工作,我需要执行以下步骤:
根据初始请求:
- 获取人员列表
- 为每个人创建 PersonEditor 并将其与 Person 对象相关联。
- 填写编辑器的数据。
关于用户操作:
- 当用户更改值并按下 Save 时,数据由 backing bean 处理。
我可以用人员列表中的数据填充编辑器,也可以将其绑定到支持 bean,但不能同时进行,所以我被卡住了。
我试过了
people.xhtml
<ui:render value="#{bean.people}" var="person">
<example:personEditor person="#{person}"/>
</ui:render>
personEditor.xhtml:
a) 与 person 对象正确关联,但与支持 bean 没有连接
<h:form>
<h:outputText value="#{cc.attr.person.name}"/>
<h:commandButton name="Save" actionListener="editorBean.save">
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
</h:form>
b) 与 person 对象没有关联,但与 backing bean 有联系 - 无法将该 person 传递给 backing bean
<h:form>
<h:outputText value="#{editorBean.name}"/>
<h:commandButton name="Save" actionListener="editorBean.save">
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
</h:form>
如果我将每个编辑器放在单独的页面上,我可以将人员 ID 作为 url 参数传递(使用 f:param 或 f:attribute)并相应地对其进行初始化。 这个问题有解决办法吗?
【问题讨论】: